简体   繁体   中英

Get an unique id for a connected network device

I am connected to a WLAN, where a special hardware device is connected to as well. I communicate to that device via a socket, since I know its IP.

Is there a was to identify that hardware device in the network by an id? I found out in Java it is not possible to obtain the MAC-address of a connected device. Is there any other alternative?

Thanks, best regards

Mac addresses should be unique. Maybe you can get needed information from the ARP table. Command "arp -a" works on Windows and Linux.

But there is a problems:

  1. This is not portable way
  2. The ARP table is quite variable
  3. If the device is behind a router, then this does not work.

In Java you can call NetworkInterface.getHardwareAddress() that will return hardware MAC address

Enumeration<NetworkInterface> enumNicList = NetworkInterface.getNetworkInterfaces();
while(enumNicList.hasMoreElements())
{
    NetworkInterface oNic = enumNicList.nextElement();
    byte[] baMacAddress = oNic.getHardwareAddress();
    String sMacAddress = new BigInteger(1, baMacAddress).toString(16);
    System.out.println(sMacAddress);
}

If you don't have any control of the responses of the device, and the device doesn't contain any identifying API calls and such, then just use the IP address and make that IP statically assigned to that device via your router. Then you can either create your own table of IP <-> device list, or even scrape the IP table off your router.

Come to think of it, you could probably get the MAC address the same way - scrape the DHCP table off your router's configuration screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM