| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1264 人关注过本帖
标题:用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
快速回复:用java读MAC地址(原创)
数据加载中...
 
   



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

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