欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.net獲取本機(jī)公網(wǎng)IP地址示例

 更新時(shí)間:2014年01月06日 09:14:55   作者:  
本文主要介紹了.net獲取本機(jī)公網(wǎng)IP地址的方法,使用了ip138的數(shù)據(jù),大家參考使用吧

代碼很簡(jiǎn)單,直接看代碼

復(fù)制代碼 代碼如下:

using System;
using System.Net;
using System.Text.RegularExpressions;

namespace Keleyi.Com
{
    public class GetInternetIP
    {
        public static string GetIP()
        {
            using (var webClient = new WebClient())
            {
                try
                {
                    var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");
                    var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;
                    return !string.IsNullOrEmpty(ip) ? ip : null;
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
        }
    }
}

相關(guān)文章

最新評(píng)論