在启动花生壳软件时, 看到界面上可以显示 adsl 的出口 IP 地址, 
如何模拟花生壳这个功能, 取得 adsl 联接 internet 的出口 IP 呢? 用 Java 可以实现这个功能吗?

解决方案 »

  1.   

    InetAddress[] all=InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
    InetAddress local=InetAddress.getLocalHost();
    //在all中.不等于local的就是.
      

  2.   


    上网方式是通过 network card -> switch -> router -> adsl modem -> internet
    照上面方式得到的结果是本地 IP 地址如下: all: 192.168.1.3
    all: win0001
    localhost: 192.168.1.3
    localhost: win0001
    如何才能得到 adsl IP 呢?
      

  3.   

    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<all.length;i++)
    {
    if(local.equals(all[i]))
    continue;
    System.out.println(all[i].getHostAddress());
    }
    }
    }