|
发表于 2020-5-12 14:00:01
|
显示全部楼层
java是不分操作系统的,跨平台的!
java可以取得mac地址的.就是用process流.
import java.io.*;
public class GetMac
{
//通过IP获取网卡地址
private String getMacAddressIP(String remotePcIP){
String str="";
String macAddress="";
try {
Process pp= Runtime.getRuntime().exec ("nbtstat -A " + remotePcIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
for (int i = 1; i <100; i++)
{
str=input.readLine();
if (str!=null)
{
if(str.indexOf("MAC Address")>1)
{ macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
break;
}
}
}
}
catch (IOException ex) {}
return macAddress;
}
//通过机器名获取网卡地址
private String getMacAddressName(String remotePcIP){
String str="";
String macAddress="";
try {
Process pp= Runtime.getRuntime().exec ("nbtstat -a " + remotePcIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
for (int i = 1; i <100; i++)
{
str=input.readLine();
if (str!=null)
{
if(str.indexOf("MAC Address")>1)
{ macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
break;
}
}
}
}
catch (IOException ex) {}
return macAddress;
}
public static void main(String[] args)
{
GetMac getmac;
getmac=new GetMac();
String mac="";
mac=getmac.getMacAddressIP("10.67.0.6");
System.out.println(mac);
mac=getmac.getMacAddressName("gxy ");
System.out.println(mac);
}
} |
|