2012-07-29 30 views
0

我也尝试使用GetIp方法(下)获得互联网IP得到正确的因特网IP,但只获得一个IP这123.22.114.5,我重新启动我的调制解调器很多次,但它仍然123.22.114.5,请帮助我。 (我使用Visual Studio 2010在Windows 7 64位)不能使用C#

(约我的英语不好对不起)

private string GetIp() 
    { 
     string extenalIp = ""; 
     string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp"; 
     string getIpRegex = @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"; 
     WebClient wc = new WebClient(); 
     UTF8Encoding utf8 = new UTF8Encoding(); 
     string requestHtml = ""; 
     try 
     { 
      requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp)); 
     } 
     catch (Exception e) 
     { 
      // do some thing with exception 
      Console.WriteLine(e.Message); 
     } 
     Regex r = new Regex(getIpRegex); 
     Match m = r.Match(requestHtml); 
     if (m.Success) 
     { 
      extenalIp = m.Value.ToString(); 
     } 
     wc.Dispose(); 
     return extenalIp; 
    } 
+0

你需要获得外部IP,这个问题有几个解决方案:http://stackoverflow.com/questions/3253701/c-sharp-get-public-external-ip-address – 2012-07-29 08:06:36

+0

是什么让你觉得123.22 .114.5不是您的互联网IP吗? – 2012-07-29 08:13:57

+0

谢谢cheeseweasel – tainguyen 2012-07-29 08:16:05

回答

1

你会得到的只是一个IP是你的ISP的外部 IP地址,当你请求一些外部网站如whatismyip

所有的ISP都有有限的静态IP地址和面向互联网的主机。 这个广域网IP地址通常被许多用户共享。

您在那里看到的IP与您的本地IP地址完全不同,因此,重新启动您的调制解调器不会改变它。

+0

有些身体可以帮我 – tainguyen 2012-07-29 16:09:42

+0

您试图检索哪个IP? – 2012-07-29 16:13:07

+0

我想检索像我在whatismyip – tainguyen 2012-07-30 03:06:00