`
丶折子戏
  • 浏览: 12266 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

用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;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics