标题:用java读MAC地址(原创)
只看楼主
zengqingcong
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-10-23
 问题点数:0 回复次数:2 
用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
江西广东
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-8-15
得分:0 
你这个里面的. . . . . . . . .这么多个 点号是什么意思啊。可不可以解释一下啊
2008-08-16 10:14
msi110
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-4-15
得分:0 
嘿嘿····
投机取巧
2008-08-16 19:18



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




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

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