Issue
I am currently developing a sort of wifi sniffer. To achieve that I use a tcpdump binary compiled for arm. But it's assume that I know the name of the Wifi Interface.
According to the SDK documentation NetworkInterface provide a getName() method.
I plan to use this method, so the first step is to get the NetworkInterface objet corresponding to my wifi interface.
To do that I use the WifiInfo to get the ip adress, then get an InetAddress corresponding to this IP and finally get an instance of NetworkInterface by using the static method getByInetAddress(InetAddress address).
Here is my code :
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray();
InetAddress addr = InetAddress.getByAddress(bytes);
NetworkInterface netInterface = NetworkInterface.getByInetAddress(addr);
Log.e("MyTemp",netInterface.getName());
The output :
SSID: Nancy-Universite, BSSID: 00:19:30:6a:a9:40, MAC: B4:07:F9:D5:7C:8C, Supplicant state: COMPLETED, RSSI: -80, Link speed: 11, Net ID: 6
But I except something like :
eth0
I also try the isVirtual() method but it doesn't compile, and I get an error message saying the method isVirtual() is not define for the type NetworkInterface.
I don't understand what is going on...
Any help will be appreciate.
Solution
Try this
for(Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces(); list.hasMoreElements();)
{
NetworkInterface i = list.nextElement();
Log.e("network_interfaces", "display name " + i.getDisplayName());
}
Answered By - angadsg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.