Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i learn my client ip with .NET?

i need my client ip from whatismyip.com. But Regex pattern is not correct i think? Can you help me this patttern?

like image 630
ALEXALEXIYEV Avatar asked Feb 16 '10 12:02

ALEXALEXIYEV


2 Answers

Have you read the comment in the obtained HTML:

Please set your code to scrape your IP from www.whatismyip.com/automation/n09230945.asp For more info, please see our "Recommended Automation Practices" thread in the Forum.

So this should get you going:

using (var client = new WebClient())
{
    Console.WriteLine(client.DownloadString(
        "http://www.whatismyip.com/automation/n09230945.asp"));
}
like image 158
Darin Dimitrov Avatar answered Sep 20 '22 12:09

Darin Dimitrov


This can be achieved way easier using the automation interface from www.whatismyip.com, so there's no need for any regex:

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);
        }
    }
like image 34
Olli Avatar answered Sep 19 '22 12:09

Olli