时间:2021-05-19
复制代码 代码如下:
package me.xuzs.sso.test;
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();
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Python简单获取网卡名称及其IP地址的方法。分享给大家供大家参考,具体如下:windows上想知道网卡和IP地址,可以使用ipconfig命令
1.配置ip地址前首先ifconfig查看网卡信息并获取到网卡的名称2.进入到网卡配置目录cd/etc/sysconfig/network-scripts/,找
获取本机所有IP地址:这些地址是包含所有网卡(虚拟网卡)的ipv4和ipv6地址。stringname=Dns.GetHostName();IPAddress[
本介绍了在C#中通过截取DOSming令输出流来获取网卡MAC地址的方法。在DOS中可以通过输入"ipconfig/all"ming令来获取网卡的MAC地址,这
以电脑为例,其网络受限是由于网卡的TCP/IP协议,设置了自动获取IP地址,然而局域网中不存在可以让其得到IP地址的DHCP服务器。 电脑(computer,