I need to get the MAC address of Gateway but didn’t find any API for that. Is there any way to get it by java in python?
You can enumerate the
NetworkInterface.getNetworkInterfaces() and each of those will have a
getHardwareAddress() on it.
Could you please give me a sample code in python script? I have some problem making it work.
from java.net import NetworkInterface e = NetworkInterface.getNetworkInterfaces() while e.hasMoreElements(): ni = e.nextElement() hwaddr = ni.getHardwareAddress() if hwaddr is not None: mac = ':'.join(format(x & 0xFF, '02x') for x in hwaddr) print "%s: %s" % (ni.getName(), mac)
llw0: 12:eb:72:12:1c:de awdl0: 12:eb:72:12:1c:de en5: ac:de:48:00:11:22 vmnet8: 00:50:56:c0:00:08 vmnet1: 00:50:56:c0:00:01 en0: f8:ff:c2:01:e4:c6