在多网卡和多IP的情况下,取得DNS对应的ip地址

InetAddress address = InetAddress.getLocalHost();

然后根据ip地址获得对应的MAC地址

try {
NetworkInterface ni = NetworkInterface
.getByInetAddress(address);
// NetworkInterface
// ni=NetworkInterface.getByInetAddress(InetAddress.getByName(“192.168.0.1″));
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
macaddress = hexByte(mac[0]) + “-” + hexByte(mac[1])
+ “-” + hexByte(mac[2]) + “-” + hexByte(mac[3])
+ “-” + hexByte(mac[4]) + “-” + hexByte(mac[5]);
} else {
System.out
.println(“Address doesn’t exist or is not accessible.”);
}
} else {
System.out
.println(“Network Interface for the specified address is not found.”);
}

}




Related posts

coded by nessus
分享:  DeliciousGReader鲜果豆瓣CSDN网摘
Trackback

2 comments untill now

  1. adopts@pram.implantation” rel=”nofollow”>.…

    áëàãîäàðñòâóþ!…

  2. zoned@boil.ceramics” rel=”nofollow”>.…

    thanks!!…

Add your comment now

无觅相关文章插件