大家好,我的电脑是双网卡,我如何才能获得外网的IP
地址呢。String localIP = InetAddress.getLocalHost().getHostAddress();使用上面的语句只能获取IP地址为127.0.0.1,我如何才能获得我的外网IP呢??(10.163.162.184)谢谢大家!

解决方案 »

  1.   

    你得说清楚点 你通过路由了么? 如果通过路由的话 这样当然获取不到   如果没有  那么获取拨号的虚了网卡地址就可以HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] 
      

  2.   

    import java.net.InetAddress;
    import java.net.UnknownHostException;public class Test1{   
        public static void main(String[] args){
         try {
         // abc123为你的主机名称
         InetAddress hosts[] = InetAddress.getAllByName("abc123");
         for( int i=0; i < hosts.length; i ++ ) {
         // 比较你的外网IP网段判断
         System.out.println(hosts[i].getHostAddress());
         }
      } catch( UnknownHostException e ) {
        }    
        }
    }