我确实尝试使用 GetIp 方法(如下)获取互联网 IP,但它只获得一个 IP,即123.22.114.5,我多次重新启动调制解调器但它仍然是123.22.114.5,请帮助我。(我在 Windows 7 64 位中使用 Visual Studio 2010)
(对不起我的英语不好)
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;
}