当前页面: 开发资料首页 → Java 专题 → 如何模拟花生壳软件功能, 取得 adsl 联接 internet 的出口 IP 呢?
如何模拟花生壳软件功能, 取得 adsl 联接 internet 的出口 IP 呢?
摘要: 如何模拟花生壳软件功能, 取得 adsl 联接 internet 的出口 IP 呢?
在启动花生壳软件时, 看到界面上可以显示 adsl 的出口 IP 地址,
如何模拟花生壳这个功能, 取得 adsl 联接 internet 的出口 IP 呢?
用 Java 可以实现这个功能吗?
InetAddress[] all=InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
InetAddress local=InetAddress.getLocalHost();
//在all中.不等于local的就是.
上网方式是通过 network card -> switch -> router -> adsl modem -> internet
照上面方式得到的结果是本地 IP 地址如下:
all: 192.168.1.3
all: win0001
localhost: 192.168.1.3
localhost: win0001
如何才能得到 adsl IP 呢?
import java.net.*;
class GetADSLIP
{
public static void main(String args[]) throws Exception
{
InetAddress[] all=InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
InetAddress local=InetAddress.getLocalHost();
for(int i=0;i
{
if(local.equals(all[i]))
continue;
System.out.println(all[i].getHostAddress());
}
}
}
你要连了网.才能看到ADSL的IP