我现在是局域网。我使用了下面代码查到的是内网的IP地址
System.Net.IPAddress[] ips;
ips = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
textBox1.Text = ips[2].ToString();
请问怎么编写查询外网IP地址的代码呢? 谢谢!

解决方案 »

  1.   

    访问 www.ip138.com
    httprequest 抓取上面的数据。
      

  2.   

    http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&biw=1260&bih=837&q=httpwebrequest+ip138+using&aq=f&aqi=&aql=&oq=
      

  3.   


     string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了   
                Uri uri = new Uri(strUrl);   
                WebRequest wr = WebRequest.Create(uri);   
                Stream s = wr.GetResponse().GetResponseStream();   
                StreamReader sr = new StreamReader(s, Encoding.Default);   
                string all = sr.ReadToEnd(); //读取网站的数据   
                int i = all.IndexOf("[") + 1;   
                string tempip = all.Substring(i, 15);   
                string ip = tempip.Replace("]", "").Replace(" ", "");   
                return ip;   我抄的,如果有偏差的地方,自己改改
      

  4.   

    4楼的代码返回值里没有本机的外网IP
    "<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="refresh" content="0;url=http://city.ip138.com/city0.asp"> <title>IP地址查询</title> </head> <body> <script type="text/javascript"> location.href="http://city.ip138.com/city0.asp"; </script>  </body> </html>"