您的位置:首页 > 其它

获取客户端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;

        }

其实整个功能实现起来代码很容易就看懂,这里就不多做解释。希望能帮到有需要的人。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mac地址 客户端