标题:用java读MAC地址(原创)
取消只看楼主
zengqingcong
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-10-23
 问题点数:0 回复次数:0 
用java读MAC地址(原创)
利用JAVA来读取本机MAC地址:代码如下

import *;
/*
 * @Author Zengqingcong
 * 2008-07-15
 */
public class ReadMacAddress {

    public String getPhysicAddress() {
        String physicalAddress = "";
        String line = "";
        try {
            Process process = Runtime.getRuntime().exec("cmd /c ipconfig /all");
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
            while ((line = bufferedReader.readLine()) != null) {
                if (line.indexOf("Physical Address. . . . . . . . . :") != -1) {
                    if (line.indexOf(":") != -1) {
                        physicalAddress = line.substring(line.indexOf(":") + 2);
                    }
                }

            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return physicalAddress;
    }

    public static void main(String[] args) {
        System.out.println("Your MacAddress is:\t"+new ReadMacAddress().getPhysicAddress());//My MacAddress is:00-16-E6-DA-AC-68
    }
}
搜索更多相关主题的帖子: MAC地址 java JAVA String line 
2008-07-14 01:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-223778-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.122831 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved