用JavaScript获取客户端ip地址

public static String getMacAddrByIpOrName(String type,String ipOrHost){
String str="";
String macAddress="";
String cmdContent = "";
if(null==type){
type = "IP";
cmdContent = "nbtstat -A " + ipOrHost;
}else if(type.equals("IP")){
cmdContent = "nbtstat -A " + ipOrHost;
}else if(type.equals("HostName")){
cmdContent = "nbtstat -a " + ipOrHost;
}
try {
Process pp= Runtime.getRuntime().exec(cmdContent);
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;
}

 

你可能感兴趣的:(生活)