import java.net.inetaddress;
import java.net.networkinterface;
import java.net.socketexception;
import java.util.enumeration;
public class internettest {
public static void main(string[] args) {
string netcard = "lo";
try {
enumeration<networkinterface> netinterfaces = networkinterface
.getnetworkinterfaces();
if (netinterfaces.hasmoreelements()) {
networkinterface netinterface = netinterfaces.nextelement();
if (netcard.equals(netinterface.getname())) {
// 子接口,linux下会取到父接口??
enumeration<networkinterface> subnetinterfaces = netinterface
.getsubinterfaces();
while (subnetinterfaces.hasmoreelements()) {
networkinterface subnetinterface = subnetinterfaces
.nextelement();
system.out.println(subnetinterface.getname());
enumeration<inetaddress> subaddresses = netinterface
.getinetaddresses();
while (subaddresses.hasmoreelements()) {
inetaddress subaddress = subaddresses.nextelement();
system.out.println(subaddress.gethostaddress());
}
}
// 打印接口下所有ip
system.out.println(netinterface.getname());
enumeration<inetaddress> addresses = netinterface
.getinetaddresses();
while (addresses.hasmoreelements()) {
inetaddress address = addresses.nextelement();
system.out.println(address.gethostaddress());
}
}
}
} catch (socketexception e) {
e.printstacktrace();
}
}
}
如对本文有疑问, 点击进行留言回复!!
unity的错误解决办法:NullReferenceException: Object reference not set to an instance of an object;tiny proje
Hadoop 之 HDFS (HDFS 数据流的 读写 流程)
听说你一读Spring源码就懵逼?我帮你把架子搭好了,你填就行!
首席架构师推荐:金融保险领域数字化转型实践--如何优雅地修改业务中台中分层应用Maven多模块的版本号?(命令导入式)
[JVM学习之路]一、初识JVM,了解其结构、模型及生命周期
网友评论