分享

用java获取系统网卡的物理地址

 毁灭号 2011-05-04
为了保证用户名的安全,将用户名和该机器的网卡物理地址进行绑定,将其保存至session中,登陆的时候检查该用户的session是否是与本机器网卡的物理地址相匹配。
package com.sdtrip.MacDemo;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LocalMacAddress
{


public static void main(String[] args)
{
String MAC = LocalMacAddress.getMacOnWindow();
System.out.println(MAC);


    }
private static String getMacOnWindow() {
    String s = "";
  
    try {
        String s1 = "ipconfig /all";
        Process process = Runtime.getRuntime().exec(s1);
        BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String nextLine;
        for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
            nextLine = bufferedreader.readLine();
            if (line.indexOf("Physical Address") <= 0) {
                continue;
            }
            int i = line.indexOf("Physical Address") + 36;
            s = line.substring(i);
            break;
        }
        bufferedreader.close();
        process.waitFor();
    } catch (Exception exception) {
        s = "";
    }
    return s.trim();
}

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多