package com.lc.test.Array;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
public class Test_NetWork {
public static void main ( String [] args ) throws SocketException, UnsupportedEncodingException {
String allipaddress;
ArrayList ar = new ArrayList();
Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
Enumeration cardipaddress = ni.getInetAddresses();
// InetAddress ip = (InetAddress) cardipaddress.nextElement();
// System.out.println(ip.getHostAddress());
ar.add(ni.getName());
// if(!ip.getHostAddress().equalsIgnoreCase("127.0.0.1") )
// { ar.add(ni.getName()+":");
// allipaddress=ip.getHostAddress();
// while(cardipaddress.hasMoreElements())
// {
// ip = (InetAddress) cardipaddress.nextElement();
// allipaddress=allipaddress+" , "+ip.getHostAddress();
// }
// ar.add(allipaddress);
// System.out.println(ip.getHostAddress());
// System.out.println(allipaddress);
// }
// else
// continue;
//
}
for(int i=0;i<ar.size();)
{
System.out.println(ar.get(i++));
}
}
}
Java获取网口数量
最新推荐文章于 2024-03-28 20:20:37 发布