//如下代码package laobao;
import java.net.InetAddress;
public class Demo01 {
public static void main(String args[]) throws Exception{
InetAddress localAddress = InetAddress.getLocalHost();
System.out.println("本地IP :" + localAddress.getHostAddress() );
}
}//结果 本地IP :111.0.229.245在cmd中 :
C:\Users\laobao>ipconfigPPP adapter VPN 连接: Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 111.0.229.245
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0
......Ethernet adapter 本地连接: Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::2975:65eb:1793:ac3f%10
IPv4 Address. . . . . . . . . . . : 10.10.221.xx
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.10.221.1 ......请问这里的 PPP adapter VPN 连接 和 Ethernet adapter 本地连接 各是什么?
结果为什么不是 本地IP :10.10.221.xx ?本人用的是学校的 锐捷 本地连接手动输入的ip 10.10.221.xx
import java.net.InetAddress;
public class Demo01 {
public static void main(String args[]) throws Exception{
InetAddress localAddress = InetAddress.getLocalHost();
System.out.println("本地IP :" + localAddress.getHostAddress() );
}
}//结果 本地IP :111.0.229.245在cmd中 :
C:\Users\laobao>ipconfigPPP adapter VPN 连接: Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 111.0.229.245
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0
......Ethernet adapter 本地连接: Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::2975:65eb:1793:ac3f%10
IPv4 Address. . . . . . . . . . . : 10.10.221.xx
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.10.221.1 ......请问这里的 PPP adapter VPN 连接 和 Ethernet adapter 本地连接 各是什么?
结果为什么不是 本地IP :10.10.221.xx ?本人用的是学校的 锐捷 本地连接手动输入的ip 10.10.221.xx
Ethernet adapter是你的物理网卡
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
public class GetIpsInfo {
public static void main(String[] args) {
Enumeration nettworkInterfaces = null;
try {
nettworkInterfaces = NetworkInterface.getNetworkInterfaces();
while (nettworkInterfaces.hasMoreElements()) {
System.out.println("---------------------------------------------------------");
NetworkInterface networkInterface = (NetworkInterface) nettworkInterfaces.nextElement();
System.out.println("DisplayName = " + networkInterface.getDisplayName());
System.out.println(" Name = " + networkInterface.getName());
Enumeration inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
System.out.println("这块网卡的IP = "
+ ((InetAddress) inetAddresses.nextElement()).getHostAddress());
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("---------------------------------------------------------");
}}
Ethernet adapter是你的物理网卡