我本地的IP地址是:192.168.1.101 ,真实IP地址是:115.192.242.230,我想要获取后面的IP地址而不是本地的应该怎么获取??用winform实现!!

解决方案 »

  1.   

    http://www.ip138.com/可以利用这种类型的网站
      

  2.   

     string hostname;
                System.Net.IPHostEntry localhost;
                System.Net.IPAddress []localaddr;            hostname = System.Net.Dns.GetHostName();
                localhost = System.Net.Dns.GetHostEntry(hostname);
                localaddr = localhost.AddressList;   //localaddr中就是本机ip地址   
      

  3.   

     string name = Dns.GetHostName();
                IPAddress[] ips = Dns.GetHostAddresses(name);
                foreach (IPAddress ip in ips)
                    Console.WriteLine(ip);如果是ADSL拨号,一般ips[1]是外网地址
    如果是路由器上网,没有外网地址的
      

  4.   

    static void Main(string[] args)
            {
                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 start= all.IndexOf("[") + 1;
                int end=all.IndexOf("]",start);
                string tempip = all.Substring(start, end - start);
                Console.WriteLine(tempip);            sr.Close();
                s.Close();
                Console.ReadLine();
            }