码迷,mamicode.com
首页 > Windows程序 > 详细

C#获取外网IP地址;C#获取所在IP城市地址

时间:2017-04-25 10:16:33      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:iframe   new   cal   mat   public   script   result   content   using   

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

        }



//表单验证
        $(function () {


            var ip = $.trim($("#hidLocalIp").val()); // "218.4.255.91";
            $.getScript(‘http://int.dpool.sina.com.cn/iplookup/iplookup.php?

format=js&ip=‘ + ip, function (_result) {
                if (remote_ip_info.ret == "1") {
                    $("#hidArea").val(ip + ";" + remote_ip_info.country + ";" + remote_ip_info.province + ";" + remote_ip_info.city + ";" + remote_ip_info.isp + ";");
                    //alert(ip + ";" + remote_ip_info.country + ";" + remote_ip_info.province + ";" + remote_ip_info.city + ";" + remote_ip_info.isp + ";"); 
                }
            }); 
        });

C#获取外网IP地址;C#获取所在IP城市地址

标签:iframe   new   cal   mat   public   script   result   content   using   

原文地址:http://www.cnblogs.com/cxchanpin/p/6760074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!