首页 > Windows开发 > 详细

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

时间:2017-04-25 09:50:09      阅读:245      评论:0      收藏:0      [点我收藏+]
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城市地址

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!