我正在开发一个安全投票系统的应用程序。我需要将特定机器的MAC地址设置为“投票机”。如何获取客户端计算机的MAC地址?
答案 0 :(得分:2)
//InetAddress address = InetAddress.getLocalHost();
InetAddress address = InetAddress.getByName("192.168.46.53");
/*
* Get NetworkInterface for the current host and then read the
* hardware address.
*/
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
/*
* Extract each array of mac address and convert it to hexa with the
* following format 08-00-27-DC-4A-9E.
*/
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
}
} else {
// Address doesn't exist or is not accessible.
}
} else {
// Network Interface for the specified address is not found.
}
答案 1 :(得分:-1)
以下是我实施的代码,它对我有用。此代码来自:Get mac address ip address in jsp java。
守则如下:
<script type="text/javascript" language="javascript">
var x = this.getElementsByClassName('getDownloadLink')[0].href; //this is not working!
</script>