如何了解我的客户端IP与.NET? [英] how can i learn my client ip with .NET?

查看:87
本文介绍了如何了解我的客户端IP与.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从whatismyip.com客户端IP。但是,正则表达式是不正确的,我认为?你能帮我这个patttern?

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

推荐答案

这是可以实现的方式更容易使用从www.whatismyip.com自动化接口,所以没有必要对任何正则表达式:

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);
        }
    }

这篇关于如何了解我的客户端IP与.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆