获取客户端Mac地址
2013-12-09 10:58
162 查看
最近需要做一个获取客户端MAc地址的功能,网上找了很多资料,先列出其功能实现:
代码如下:
public String getMACAddress(String ip){
String str = "";
String macAddress = "";
try {
String scancmd="nbtstat -A "; //64位和32位系统过滤
File file = new File("C:\\Windows\\SysWOW64");
if(file.exists()){
scancmd = "c:\\Windows\\sysnative\\nbtstat.exe -A ";
}
Process p = Runtime.getRuntime().exec(scancmd + ip);
InputStreamReader ir = new InputStreamReader(p.getInputStream(),"GBK"); //使用GBK
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC 地址") > 1) {
macAddress = str.substring(str.indexOf("=") + 1, str.length());
break;
}
}
if (str.indexOf("MAC Address")>0) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
}
} catch (IOException e) {
e.printStackTrace(System.out);
}
return macAddress;
}
其实整个功能实现起来代码很容易就看懂,这里就不多做解释。希望能帮到有需要的人。
代码如下:
public String getMACAddress(String ip){
String str = "";
String macAddress = "";
try {
String scancmd="nbtstat -A "; //64位和32位系统过滤
File file = new File("C:\\Windows\\SysWOW64");
if(file.exists()){
scancmd = "c:\\Windows\\sysnative\\nbtstat.exe -A ";
}
Process p = Runtime.getRuntime().exec(scancmd + ip);
InputStreamReader ir = new InputStreamReader(p.getInputStream(),"GBK"); //使用GBK
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC 地址") > 1) {
macAddress = str.substring(str.indexOf("=") + 1, str.length());
break;
}
}
if (str.indexOf("MAC Address")>0) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
}
} catch (IOException e) {
e.printStackTrace(System.out);
}
return macAddress;
}
其实整个功能实现起来代码很容易就看懂,这里就不多做解释。希望能帮到有需要的人。
相关文章推荐
- JavaScript获取客户端IP和MAC地址
- 使用nginx等反向代理时获取Windows版客户端真实的ip及mac地址
- Java获取访问服务端的客户端IP和MAC地址
- web程序获取客户端MAC地址
- ASP.NET获取客户端IP及MAC地址
- PHP获取客户端的网卡mac物理地址
- JS获取客户端网卡物理地址(MAC)
- asp.net获取客户端的MAC(网卡地址)
- java 获取客户端ip mac地址
- ASP.NET获取客户端IP及MAC地址
- ASP.NET获取客户端IP及MAC地址
- ASP.NET获取客户端IP及MAC地址
- JS获取客户端网卡物理地址(MAC) 代码
- php获取客户端mac地址的实例分享
- ASP.NET获取客户端网卡使用的MAC地址信息
- 获取客户端网卡的MAC地址
- php获取服务器端mac和客户端mac的地址
- asp.net如何获取客户端网卡mac地址
- php获取服务器端mac和客户端mac的地址支持WIN/LINUX