Krishan
Krishan

Reputation: 641

JpcapCaptor.getDeviceList() returns an empty array

I'm new to Jpcap. I'm using

NetworkInterface[] arr=JpcapCaptor.getDeviceList();
System.out.println(arr.length);

to get the devices from Jpcap. But it returns an empty array. When I print the length of the array, it is 0. I' using ubuntu 11.10 and installed libpcap using sudo apt-get install libpcap-dev. I have jpcap.jar in my classpath. I don't understand why I'm not getting any Network Devices. Can someone help me.

EDIT: When I run ifconfig in terminal I get this output.

eth0 Link encap:Ethernet HWaddr 18:a9:05:cb:8d:fb
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:17

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:758 errors:0 dropped:0 overruns:0 frame:0 TX packets:758 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:27296 (27.2 KB) TX bytes:27296 (27.2 KB)

wlan0 Link encap:Ethernet HWaddr 00:26:c6:14:6c:68
inet addr:192.168.2.55 Bcast:192.168.3.255 Mask:255.255.252.0 inet6 addr: fe80::226:c6ff:fe14:6c68/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:11385 errors:0 dropped:0 overruns:0 frame:0 TX packets:6088 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4582447 (4.5 MB) TX bytes:1203113 (1.2 MB)

Upvotes: 1

Views: 1431

Answers (1)

Krishan
Krishan

Reputation: 641

I had the problem when I run in Ubuntu 11.10 and netbeans. When I try to run the jar file using the terminal (with sudo permissions) it worked. I think the issue is with permissions in linux.

Running the .jar file in the terminal sudo java -jar YourJarFile.jar would solve he issue.

Upvotes: 2

Related Questions