Java代码
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class Test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Properties pp = System.getProperties(); //获取系统的所有属性
pp.list(System.out);//打印所有的属性
String command = "cmd.exe /c ipconfig/all ";
Process p = Runtime.getRuntime().exec(command);//执行DOS程序
System.out.println(p);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
String address = "";
while ((line = br.readLine()) != null) {
System.out.println(line);
if (line.indexOf("Physical Address") > 0) {//如果有Physical Address字符串
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
System.out.println(address);
}
}
分享到:
相关推荐
java获取mac,通过命令获取裁剪后得到想要的内容
执行main方法获取mac地址,最权威的demo自己测试已经正常使用。网上基本都是假的获取不到,只有我这个才是最方便的
### Java 获取客户端 IP 和 MAC 地址 在Java Web开发中,有时我们需要获取客户端的IP地址甚至是MAC地址,以便进行安全验证、用户行为追踪等操作。本文将详细介绍如何通过Java来实现这一功能。 #### 一、获取客户端...
在对网内主机进行监控时需要通过java获取远程机器的mac地址
java获取不同操作系统的名称以及mac地址工具类,例如:windows,Linux,Unix等