读取本地外网IP地址

读取本地外网IP地址.

根据启动并运行的网卡名称,找到本机实际的IP地址(已知当前运行的无线网卡名包含某一个字符)

import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List; public class URL{
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
printParameter(ni); }
} public static void printParameter(NetworkInterface ni)
throws SocketException {
//if (null != ni.getDisplayName()&& ni.getDisplayName().contains("Wireless") && ni.isUp()) {
System.out.println(" Name = " + ni.getName());
System.out.println(" Display Name = " + ni.getDisplayName());
System.out.println(" Is up = " + ni.isUp());
System.out.println(" Support multicast = " + ni.supportsMulticast());
System.out.println(" Is loopback = " + ni.isLoopback());
System.out.println(" Is virtual = " + ni.isVirtual());
System.out.println(" Is point to point = " + ni.isPointToPoint());
System.out.println(" Hardware address = " + ni.getHardwareAddress());
System.out.println(" MTU = " + ni.getMTU());
System.out.println("\nList of Interface Addresses:");
List<InterfaceAddress> list = ni.getInterfaceAddresses();
Iterator<InterfaceAddress> it = list.iterator(); while (it.hasNext()) {
InterfaceAddress ia = it.next();
if(null!=ia.getBroadcast()){
System.out.println(" 联网网卡IPv4地址: " + ia.getAddress().getHostAddress());
}
} System.out .println("**************************************************");
// }
}
}

装载:

http://bbs.csdn.net/topics/390904895

上一篇:洛谷 P2149 [SDOI2009]Elaxia的路线 解题报告


下一篇:python中使用os.path.join()