我需要我的客户IP来自whatismyip.com。但是我认为正则表达式模式不正确吗?您能帮我这个方式吗?
最佳答案
可以使用www.whatismyip.com上的自动化界面更轻松地实现此目的,因此不需要任何正则表达式:
static void Main(string[] args)
{
const string url = "http://www.whatismyip.com/automation/n09230945.asp";
var client = new WebClient();
try
{
var myIp = client.DownloadString(url);
Console.WriteLine("Your IP: " + myIp);
}
catch (Exception ex)
{
Console.WriteLine("Error contacting website: " + ex.Message);
}
}