请问怎么获取本局域网的子网掩码呀? 请问怎么获取本局域网的子网掩码呀?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用JAVA调用系统的PING命令(windows,linux则是调用另一个相应命令),然后读取相应字符串。曾经有次网络的小实验就是任选门语言获取本机的MAC地址,最后我是通过这种方式实现的,不过很麻烦...看别人还有更好的办法没 ....打错了...是ipconfigRI,真失败- -! import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class MaskAddress { public MaskAddress() { } public static String getMaskAddress() { String address = null; 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("Subnet Mask") > 0) { int index = line.indexOf(":"); index += 2; address = line.substring(index); break; } } br.close(); return address.trim(); } catch (IOException e) {} } return address; } public static void main(String[] args) { System.out.println("子网掩码:"+MaskAddress.getMaskAddress());}}利用ipconfig命令得到的,应该还有其它更好的办法我想。 肯定有,调用cmd的话,java的优势何在啊?都和操作系统捆绑了 不啊,没捆绑呀?我开始不就说了么,如果是linux就调用另外的命令。由if (os != null && os.startsWith("Windows")) 来判断你使用的操作系统,因为我估计LZ要的是WINDOWS下的,所以就只写了Windows部分。把其余操作系统的实现部分给添加上不就不限于特定系统了,何来捆绑不过还是希望能有更简单的操作就能得到这些信息就好了 递归问题 再问正则表达式,如何匹配整个单词或者各个字符? java编写服务器传送图片问题 动态代理的问题 java统计txt文件内的中英文字数问题 听说12月16日有个java技术研讨会,有那位同仁报名了~~ 关于addWindowListener()和scrollRectToVisible 函数! 怎么获取客户端的MAC地址 请问java数据库程序中如何用图表示数据库中的数值? 如何设置该class的import路径?在线等....... 求Zelix KlassMaster下载 JNI参数传递
曾经有次网络的小实验就是任选门语言获取本机的MAC地址,最后我是通过这种方式实现的,不过很麻烦...看别人还有更好的办法没
RI,真失败- -!
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class MaskAddress {
public MaskAddress() {
} public static String getMaskAddress() { String address = null;
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("Subnet Mask") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {}
}
return address;
} public static void main(String[] args) {
System.out.println("子网掩码:"+MaskAddress.getMaskAddress());
}
}
利用ipconfig命令得到的,应该还有其它更好的办法我想。
我开始不就说了么,如果是linux就调用另外的命令。
由if (os != null && os.startsWith("Windows")) 来判断你使用的操作系统,因为我估计LZ要的是WINDOWS下的,所以就只写了Windows部分。
把其余操作系统的实现部分给添加上不就不限于特定系统了,何来捆绑不过还是希望能有更简单的操作就能得到这些信息就好了