高手们!请问JAVA中如何获取主机MAC地址呢? 高手们!请问JAVA中如何获取主机MAC地址呢?如果知道的能否指点一二。谢谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;public class getMAC { public static String getMACAddress() { String address = ""; String os = System.getProperty("os.name"); if ( os != null && os.startsWith("Windows")) { try { String command = "cmd.exe /c ipconfig /all"; Process p = Runtime.getRuntime().exec(command); BufferedReader br =new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = br.readLine()) != null) { if (line.indexOf("Physical Address") > 0) { int index = line.indexOf(":"); index += 2; address = line.substring(index); } } br.close(); System.out.println(address.trim()); } catch (IOException e) { } } return address;}public static void main(String[] args) { getMAC getmac; getmac=new getMAC(); String f=getmac.getMACAddress(); //System.out.println(f); }}看看,这样一个行不行,我写的 发布一个Java写的俄罗斯方块源码 异常问题 Scanner(System.in) 输入特定的字符,自动停止输入? 一个根据数据库的值自动返回单选复选框是否被选中的问题 java中接口是否可以成为其他类的属性 请问谁有jdk的pdf文挡或者word格式的或者tutorial的pdf格式的 对JAVA不熟悉,帮忙优化一下下面的程序 在java中能不能调用oracle的package 如何将java.util.Date转化成java.sql.Date? java中有没有计时器? 这两句代码有什么不同? jdbc问题,为什么找不到类库
public class getMAC
{
public static String getMACAddress() { String address = "";
String os = System.getProperty("os.name");
if ( os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br =new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
}
}
br.close();
System.out.println(address.trim());
}
catch (IOException e) { }
}
return address;
}
public static void main(String[] args)
{
getMAC getmac;
getmac=new getMAC();
String f=getmac.getMACAddress();
//System.out.println(f); }
}
看看,这样一个行不行,我写的