Linux下如何获取本机mac地址? 诸位Linux下如何获得本机的mac地址!给个实例小程序供参考?java语言可以吗?还有怎么通过java程序去修改本机mac地址!!急!望知道的大侠给予回复!谢谢...... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.lxh.test;import java.io.*;/* * lxh */public class Test { public static void main(String[] args) throws Exception { String line; String physicalAddress = "read MAC error!"; try { Process p=Runtime.getRuntime().exec("cmd.exe /c ipconfig /all"); //p.waitFor(); BufferedReader bd =new BufferedReader(new InputStreamReader (p.getInputStream())); while((line=bd.readLine())!=null){ if(line.indexOf("Physical Address. . . . . . . . . :")!=-1){ if(line.indexOf(":")!=-1){ physicalAddress = line.substring(line.indexOf(":")+2); break; //找到MAC,推出循环 } } } p.waitFor(); System.out.println("信息:"+line+" "); System.out.println("本机的MAC地址是: "+ physicalAddress); } catch (IOException e) { e.printStackTrace(); } }}MAC地址是全球唯一的 不能被修改的 解析ifconfig命令。import java.io.*;import java.util.regex.*;public class GetMac{ public static void main(String arsg[])throws Exception{ String mac=""; String cmd="ifconfig"; Process p=Runtime.getRuntime().exec(cmd); java.io.InputStream in=p.getInputStream(); java.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(in)); String line=null; String ip=null; while((line=br.readLine())!=null){ if(line.indexOf("HWaddr")!=-1){ Matcher m=Pattern.compile("([0-9A-F]{2,2}:){5,5}[0-9A-F]{2,2}").matcher(line); if(m.find())mac=m.group(); break; } } in.close(); br.close(); System.out.println("mac="+mac); }} 兄弟们,问个问题 jquery无法多次调用servlet(在线等) 请问现在初学struts,是应该学struts1还是struts2? Resin3.0 Servlet问题 如何让多个项目使用同一个数据源 java 与 dos 请问哪有weblogic7.0下载呀,我想照着书学j2ee,可我的weblogic版本高了,我的jbuilder8不支持。 关于JAVADOC如何解决多级目录的文档制作 100求助jdom生成xml的例子 EJB为何部署不成功? 求助:Hibernate调用存储过程 hibernate的session什么时候用手动关闭
/*
* lxh
*/public class Test {
public static void main(String[] args) throws Exception {
String line;
String physicalAddress = "read MAC error!";
try {
Process p=Runtime.getRuntime().exec("cmd.exe /c ipconfig /all");
//p.waitFor();
BufferedReader bd =new BufferedReader(new InputStreamReader (p.getInputStream()));
while((line=bd.readLine())!=null){
if(line.indexOf("Physical Address. . . . . . . . . :")!=-1){
if(line.indexOf(":")!=-1){
physicalAddress = line.substring(line.indexOf(":")+2);
break; //找到MAC,推出循环
}
}
}
p.waitFor();
System.out.println("信息:"+line+" ");
System.out.println("本机的MAC地址是: "+ physicalAddress);
} catch (IOException e) {
e.printStackTrace();
}
}}
MAC地址是全球唯一的 不能被修改的
解析ifconfig命令。
import java.io.*;
import java.util.regex.*;
public class GetMac{
public static void main(String arsg[])throws Exception{
String mac="";
String cmd="ifconfig";
Process p=Runtime.getRuntime().exec(cmd);
java.io.InputStream in=p.getInputStream();
java.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(in));
String line=null;
String ip=null;
while((line=br.readLine())!=null){
if(line.indexOf("HWaddr")!=-1){
Matcher m=Pattern.compile("([0-9A-F]{2,2}:){5,5}[0-9A-F]{2,2}").matcher(line);
if(m.find())mac=m.group();
break;
}
}
in.close();
br.close();
System.out.println("mac="+mac);
}
}