Since I am having trouble with lookupDevices() on Mac OS X (see previous thread), I started looking into the built in java.net methods. The following seems to work for getting a list of all devices:
I see no problems with it. But thanks for the code. I finally got the device names using your code here after waiting forever to get them from jpcap :).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
lookupDevices() seems to working fine for me. 1.16 now comes with device description. All u have to do is extract device name and description separately. substring(int,int) works fine for me. Any one having problem in closing capture session by using close() or endCapture() ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying 1.16, my output of lookupDevices() is the same as 1.15:
\Device\NPF_{018256CB-3833-4312-95E5-9F8CAC7882E0}
\Device\NPF_{040CAF8F-158A-4920-BD99-E984E4EED811}
\Device\NPF_{E513E3EC-0395-4EE1-83B7-E915D5B19999}
how to retrieve the device description? some code should clear it up.
thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But one the the device is showing 'extra info'
\Device\NPF_{018256CB-3833-4312-95E5-9F8CAC7882E0}
Realtek RTL8139/810x Family Fast Ethernet NIC (Microsoft's Packet Scheduler)
which should be only "Realtek RTL8139/810x Family Fast Ethernet NIC", the "(Microsoft's Packet Scheduler)" should not be there, a bug or a feature? =)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
NetworkInterface.getNetworkInterfaces() is new since JDK1.4.
Jpcap works on a variety of platforms and Java VM's, including JDK1.2 and JDK1.3.
These older VM's are still widely in use on some platforms.
So, by using libpcap's pcap_lookupdev() via lookupDevices(), a higher degree of backward compatibility is achieved than by using NetworkInterface.getNetworkInterfaces().
-pat
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes it does give you a higher degree of backward compatibility to use libpcap. And if anyone can easily and reliably map the output of lookupDevices() and NetworkInterface.getNetworkInterfaces() to each other, please let me know. Right now I can only guess..
However, the current implementation of lookupDevices() returns an array of strings, where the name is concatenated to the end of the id. Now please please make a new method that instead of just returning a string array, will at least return a two dimensional string array with the names separate from the ids. Preferrably some object orientation would be nice too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On Unix, lookupDevices returns an array of strings like: ["lo", "eth0", "eth1", "eth2"]
There aren't any descriptions, and any of the elements should work as an interface name when passed to the packet capture engine.
On Windows, I believe that the NDIS names are very long decorated strings, and the fact that Windows users couldn't figure out which of these long strings was associated with which network interface caused people to repeatedly submit patches which appends the dev name. It would be nice if Windows/winpcap had simple device names like Mac OS X, Solaris, Linux and others, but it doesn't.
Submit quality code and we'll use it.
thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since I am having trouble with lookupDevices() on Mac OS X (see previous thread), I started looking into the built in java.net methods. The following seems to work for getting a list of all devices:
Object [] deviceList;
ArrayList jDevsList = new ArrayList();
try {
Enumeration e = NetworkInterface.getNetworkInterfaces();
while( e.hasMoreElements() )
jDevsList.add(((NetworkInterface) e.nextElement()).getName());
} catch (Exception e) {}
deviceList = jDevsList.toArray();
The deviceList can then be used in a swing JcomboBox for the user to select a device. Does anyone see why this wouldn't work?
-john
I see no problems with it. But thanks for the code. I finally got the device names using your code here after waiting forever to get them from jpcap :).
lookupDevices() seems to working fine for me. 1.16 now comes with device description. All u have to do is extract device name and description separately. substring(int,int) works fine for me. Any one having problem in closing capture session by using close() or endCapture() ?
I'm trying 1.16, my output of lookupDevices() is the same as 1.15:
\Device\NPF_{018256CB-3833-4312-95E5-9F8CAC7882E0}
\Device\NPF_{040CAF8F-158A-4920-BD99-E984E4EED811}
\Device\NPF_{E513E3EC-0395-4EE1-83B7-E915D5B19999}
how to retrieve the device description? some code should clear it up.
thanks
I had the same problem. Turned out I had missed one of the jpcap.dll files - I was actually still using the 1.15 dll.
String deviceList[] = PacketCapture.lookupDevices();
for(int i=0; i<deviceList.length; i++) {
int lineBreakIndex = deviceList[i].indexOf('\n');
String deviceName = deviceList[i].substring(0,lineBreakIndex);
String deviceDescription = deviceList[i].substring(lineBreakIndex+1);
// use name/description
}
thanks for the pointer..
But one the the device is showing 'extra info'
\Device\NPF_{018256CB-3833-4312-95E5-9F8CAC7882E0}
Realtek RTL8139/810x Family Fast Ethernet NIC (Microsoft's Packet Scheduler)
which should be only "Realtek RTL8139/810x Family Fast Ethernet NIC", the "(Microsoft's Packet Scheduler)" should not be there, a bug or a feature? =)
NetworkInterface.getNetworkInterfaces() is new since JDK1.4.
Jpcap works on a variety of platforms and Java VM's, including JDK1.2 and JDK1.3.
These older VM's are still widely in use on some platforms.
So, by using libpcap's pcap_lookupdev() via lookupDevices(), a higher degree of backward compatibility is achieved than by using NetworkInterface.getNetworkInterfaces().
-pat
Yes it does give you a higher degree of backward compatibility to use libpcap. And if anyone can easily and reliably map the output of lookupDevices() and NetworkInterface.getNetworkInterfaces() to each other, please let me know. Right now I can only guess..
However, the current implementation of lookupDevices() returns an array of strings, where the name is concatenated to the end of the id. Now please please make a new method that instead of just returning a string array, will at least return a two dimensional string array with the names separate from the ids. Preferrably some object orientation would be nice too.
ps.
I've added some notes in the code regarding this alternative to lookupDevices that you've proposed.
Perhaps we'll enable it in a future version of jpcap.
thanks,
-pat
I'm not sure what you're talking about.
On Unix, lookupDevices returns an array of strings like: ["lo", "eth0", "eth1", "eth2"]
There aren't any descriptions, and any of the elements should work as an interface name when passed to the packet capture engine.
On Windows, I believe that the NDIS names are very long decorated strings, and the fact that Windows users couldn't figure out which of these long strings was associated with which network interface caused people to repeatedly submit patches which appends the dev name. It would be nice if Windows/winpcap had simple device names like Mac OS X, Solaris, Linux and others, but it doesn't.
Submit quality code and we'll use it.
thanks.
btw.
Another problem with the non-native code proposed above is that it does not return 'valid' device names on the Windows platform.
On windows, the JVM returns device names similar to Unix, e.g. eth0. Winpcap, however, needs the NDIS device name.
So, in addition to not being backward compatible with older VM's, the code is not portable (namely to Windows).
Too bad. Maybe in a future version of winpcap?
-pat