如何用java获得子网掩码? 大家好!如何用java获得子网掩码?包括linux和windows下的,有什么类可用?最好给出些代码,谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 20?? 现在的知识,越来越不值钱了 public static void main(String[] args) { try { Enumeration<NetworkInterface> eni = NetworkInterface.getNetworkInterfaces(); while (eni.hasMoreElements()) { NetworkInterface ni = eni.nextElement(); List<InterfaceAddress> lia = ni.getInterfaceAddresses(); Iterator<InterfaceAddress> iia = lia.iterator(); while (iia.hasNext()) { InterfaceAddress ia = iia.next(); InetAddress a = ia.getAddress(); if (!a.isLoopbackAddress()) { String ha = a.getHostAddress(); System.out.println("address = " + ha); short ml = (short) (ia.getNetworkPrefixLength() / 8); String[] as = ha.split("\\."); String ns = ""; for (int i = 0; i < ml; i++) { ns += as[i]; if (i < ml - 1) { ns += "."; } } System.out.println("subnet = " + ns); } } } } catch (Exception e) { e.printStackTrace(); } } 求解一道JAVA笔试题 Java中关于静态方法的疑问 又又正表达式问题 遍个程序,将浮点数转成人民币读法字符串 笔试题:编程计算一个字符串类型的四则运算表达式的值 java中数组的问题.谢谢. C++程序员想学JAVA应该看哪些书比较好啊?? 有一个JNI的问题 help me 还有两题 简单问题,关于继承 如何引用别的工程中的package?谢谢
try {
Enumeration<NetworkInterface> eni = NetworkInterface.getNetworkInterfaces();
while (eni.hasMoreElements()) {
NetworkInterface ni = eni.nextElement();
List<InterfaceAddress> lia = ni.getInterfaceAddresses();
Iterator<InterfaceAddress> iia = lia.iterator();
while (iia.hasNext()) {
InterfaceAddress ia = iia.next();
InetAddress a = ia.getAddress();
if (!a.isLoopbackAddress()) {
String ha = a.getHostAddress();
System.out.println("address = " + ha);
short ml = (short) (ia.getNetworkPrefixLength() / 8);
String[] as = ha.split("\\.");
String ns = "";
for (int i = 0; i < ml; i++) {
ns += as[i];
if (i < ml - 1) {
ns += ".";
}
}
System.out.println("subnet = " + ns);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}