如何判断两个IP地址是否指向同一台机器 例如本机的IP地址是192.168.0.1那么通过Java代码如何判断下面两个地址127.0.0.1192.168.0.1是指向同一台机器呢java代码在本机运行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 或者判断一个InetAddress是否是本地IP也行 InetAddress.getAllByName(String host);不知道行不。--------------------------或者通过通过查找IP Address内容行不?例如下面有两个或者自己调用winapi struct hostent * gethostbyname(const char *name);hostent 包含一个char **h_addr_list 就是所有的ip >ipconfig/allWindows IP Configuration Host Name . . . . . . . . . . . . : chinese-c3e460f Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Mixed IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : mshome.netEthernet adapter 本地连接: Connection-specific DNS Suffix . : mshome.net Description . . . . . . . . . . . : Realtek RTL8139 Family PCI Fast Ethernet NIC Physical Address. . . . . . . . . : 00-40-46-01-62-8C Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.0.57 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.0.1 DHCP Server . . . . . . . . . . . : 192.168.0.1 DNS Servers . . . . . . . . . . . : 192.168.0.1 Lease Obtained. . . . . . . . . . : 2005年12月12日 15:26:47 Lease Expires . . . . . . . . . . : 2005年12月19日 15:26:47PPP adapter Vnet_PPPoE: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface Physical Address. . . . . . . . . : 00-53-45-00-00-00 Dhcp Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : 61.141.226.59 Subnet Mask . . . . . . . . . . . : 255.255.255.255 Default Gateway . . . . . . . . . : 61.141.226.59 DNS Servers . . . . . . . . . . . : 202.96.134.133 202.96.128.166 NetBIOS over Tcpip. . . . . . . . : Disabled InetAddress.getAllByName(String host);会返回一个数组InetAddress[] InetAddress[] add1 = InetAddress.getAllByName("localhost")中会返回一个元素,是127.0.0.1 我不能为了这一点点小小的功能去调用win32Api,执行系统命令也不妥,况且linux下还是ifconfig,windows下是ipconfig 如果非127.0.0.1就可以InetAddress.getByName("192.168.0.1").getHostName(); --tinyjimmyInetAddress.getByName("192.168.2.1").getHostName(); --tinyjimmy而127.0.0.1被解析成localhost了对127.0.0.1特殊处理应该就可以了吧 public void getID() throws Exception { String s = "10.0.0.233"; InetAddress[] ia = InetAddress.getAllByName("cncomp-dew3qujo"); System.out.println("本机IP = " + InetAddress.getLocalHost()); for (int i = 0; i < ia.length; i++) { if (s.equals(ia[i].getHostAddress())) System.out.println(ia[i].getHostAddress() + " 是本机IP"); } } 但是在机器名未知的情况下如何读出所有的IP地址呢一个应用部署在多台机器,所以机器名是不固定的InetAddress.getAllByName("localhost");只能取到一个IP地址的 双网卡的IP也算,一个网卡设置了多个IP也算同一台机器SNMP就扯远了吧,还得依赖于系统的SNMP Agent还要第三方的SNMP开发包 一个简单关于字符拼接问题 定义属性为 null 与 直接写分号有什么区别 如何用非new的方法初始化容器类? java 中输入输出流问题 Java UDP多播的问题 请问各位大哥 怎么 装JDK1.5 怎么将光标自动定位在出错的文本框? 学习JAVA遇到问题请大家帮帮忙,是个小问题!谢谢 请问一个有关java编译的问题,谢谢 如何将一个字符串转换成数值型数据?注(是将String转numeric,不是转Float,Double,Integer) 如何使用Java自带的正则表达式? 如何用JAVA得到硬盘空间
--------------------------
或者通过
通过查找IP Address内容行不?例如下面有两个或者自己调用winapi
struct hostent * gethostbyname(const char *name);hostent 包含一个char **h_addr_list 就是所有的ip >ipconfig/allWindows IP Configuration Host Name . . . . . . . . . . . . : chinese-c3e460f
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Mixed
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : mshome.netEthernet adapter 本地连接: Connection-specific DNS Suffix . : mshome.net
Description . . . . . . . . . . . : Realtek RTL8139 Family PCI Fast Ethe
rnet NIC
Physical Address. . . . . . . . . : 00-40-46-01-62-8C
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.0.57
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
DHCP Server . . . . . . . . . . . : 192.168.0.1
DNS Servers . . . . . . . . . . . : 192.168.0.1
Lease Obtained. . . . . . . . . . : 2005年12月12日 15:26:47
Lease Expires . . . . . . . . . . : 2005年12月19日 15:26:47PPP adapter Vnet_PPPoE: Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 61.141.226.59
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 61.141.226.59
DNS Servers . . . . . . . . . . . : 202.96.134.133
202.96.128.166
NetBIOS over Tcpip. . . . . . . . : Disabled
InetAddress.getByName("192.168.2.1").getHostName(); --tinyjimmy而127.0.0.1被解析成localhost了对127.0.0.1特殊处理应该就可以了吧
String s = "10.0.0.233";
InetAddress[] ia = InetAddress.getAllByName("cncomp-dew3qujo");
System.out.println("本机IP = " + InetAddress.getLocalHost());
for (int i = 0; i < ia.length; i++) {
if (s.equals(ia[i].getHostAddress()))
System.out.println(ia[i].getHostAddress() + " 是本机IP");
}
}
一个应用部署在多台机器,所以机器名是不固定的InetAddress.getAllByName("localhost");
只能取到一个IP地址的
还要第三方的SNMP开发包