很抱歉这个愚蠢的问题,但是如何在不知道并使用JAVA中的IP地址的情况下找到网卡的MAC地址。
谢谢你, VLAD。
答案 0 :(得分:1)
您可以使用NetworkInterface.getHardwareAddress
。您可以使用NetworkInterface.getNetworkInterfaces()
获取所有网卡的列表。
您可以使用此代码了解MAC地址。
InetAddress address = InetAddress.getLocalHost();
NetworkInterface nwi = NetworkInterface.getByInetAddress(address);
byte mac[] = nwi.getHardwareAddress();
System.out.println(mac);
答案 1 :(得分:0)
您可以使用如下所示的系统命令(如果您在nix
系统上,如果您的操作系统是以类似方式使用ipconfig
的话):
Runtime r = Runtime.getRuntime();
Process p = r.exec("ifconfig -u |grep ether");
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = b.readLine()) != null) {
System.out.println(line);
}
b.close();
在我的系统上,它给出了:
ether 28:37:37:15:3b:31
ether b2:00:10:65:56:41
...
请注意,可能有很多MAC地址,蓝牙,以太网,WIFI等。