各位大虾,有谁能用JAVA取得本机的网卡地址的啊?小弟253了 InetAddress.getLocalHost().getHostAddress(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没用,这个只能获取IP地址,不是MAC地址 InetAddress.getLocalHost().getHostAddress(); 没办法,现在很多的做法是调用本地的程序ipconfig(在windows下,在linux下就是调另外的命令),然后取得信息搜一下,论坛上有的 就是楼上所说的方法:private static String getMacOnWindow() { String s = ""; try { String s1 = "ipconfig/all"; Process process = Runtime.getRuntime().exec(s1); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(process.getInputStream())); String nextLine; for (String line = bufferedreader.readLine(); line != null; line = nextLine) { nextLine = bufferedreader.readLine(); if (line.indexOf("Physical Address") <= 0) { continue; } int i = line.indexOf("Physical Address") + 36; s = line.substring(i); break; } bufferedreader.close(); process.waitFor(); } catch (Exception exception) { s = ""; } return s.trim(); } JAVA反射问题,关于反射后找寻方法的问题 Java中如何实现同一窗口的替换 小弟做的小孩做算术的题目,省的自己出题目了。 关于属性验证的问题 问下怎么用keyboard输入 今天买到《Java就业培训教程》了,谈下感受!!! 关于0、1背包问题 求大神看看哪里错了 protected的方法和变量不是不能在类外访问马? a += b 和 a = a + b有区别? java 多线程调用方法 [请教]:java中的vector问题 图形用户界面组件GridBagLayout布局管理器
现在很多的做法是调用本地的程序ipconfig(在windows下,在linux下就是调另外的命令),然后取得信息
搜一下,论坛上有的
private static String getMacOnWindow() {
String s = "";
try {
String s1 = "ipconfig/all";
Process process = Runtime.getRuntime().exec(s1);
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String nextLine;
for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
nextLine = bufferedreader.readLine();
if (line.indexOf("Physical Address") <= 0) {
continue;
}
int i = line.indexOf("Physical Address") + 36;
s = line.substring(i);
break;
} bufferedreader.close();
process.waitFor();
} catch (Exception exception) {
s = "";
}
return s.trim();
}