I'm just trying to get automatically the active device on my System.
For Example:
My PC has two devices. 1. TAP-Windows Adapter V9 2. Intel(R) Ethernet Connection
Actually the active device is the Intel Connection.
So I want that my application can automatically use the active device to dump a pcap.
My Idea is to search for the Subnetmask in both devices. The active device has an INET4 IP like this mask=[INET4: 255.255.255.0]. The deactive one gives me this: mask=[0]
Is it the right thinking, that an active device never gets a mask of 0?
This extends also for the broadcast.
Here is my implementation:
static public PcapIf selectActiveDev(List alldevs){ PcapIf device = new PcapIf();
for(int a = 0; a<=alldevs.size()-1; a++){
if(alldevs.get(a).getAddresses().get(0).getNetmask().toString() != "0"){
device = alldevs.get(a);
}
}
return device;
}
I'm using JNetPcap 1.3.0 with eclipse. :)