Esempio n. 1
0
        /// <summary>
        /// (测试用)获取IP地址多接口比较
        /// </summary>
        /// <returns></returns>
        public static List <EnpotIPAddressModel> TestGetIPAddressAdv(string ipAddress)
        {
            string arg_Ip = string.Empty;

            arg_Ip = ipAddress;
            if (!IPAddressUtils.IsIP(arg_Ip))
            {
                throw new Exception("错误:无效IP信息。");
            }

            List <EnpotIPAddressModel> all = new List <EnpotIPAddressModel>();

            all.Add(IPAddressUtils.SinaGetIPAddress(arg_Ip));
            //all.Add(IPAddressUtils.BaiduGetIPAddress(arg_Ip));
            //all.Add(IPAddressUtils.TaobaoGetIPAddress(arg_Ip));

            return(all);
        }
Esempio n. 2
0
        ///// <summary>
        ///// (弃用)获取IP地址
        ///// 只获取新浪接口返回信息,已改用 GetIPAddressAdv,从多个接口获取后比较获取最佳结果
        ///// </summary>
        ///// <returns></returns>
        //public static EnpotIPAddressModel GetIPAddress()
        //{
        //    string arg_Ip = IPAddressUtils.GetRequestIP();
        //    //arg_Ip = "205.251.196.138";

        //    if (!IPAddressUtils.IsIP(arg_Ip))
        //    {
        //        throw new Exception("错误:无效IP信息。");
        //    }

        //    string url = string.Format("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip={0}", arg_Ip);
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        //    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //    System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
        //    string tmpString = sr.ReadToEnd();

        //    SinaIPAddressModel tmpIpAddressModel = null;
        //    try
        //    {
        //        tmpIpAddressModel = JsonConvert.DeserializeObject<SinaIPAddressModel>(tmpString);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception("错误:转换Json信息失败。", ex);
        //    }
        //    EnpotIPAddressModel result = new EnpotIPAddressModel(arg_Ip, tmpIpAddressModel);
        //    result.Device = IPAddressUtils.GetUserAgent();
        //    return result;
        //}

        /// <summary>
        /// 获取IP地址 多接口比较版
        /// </summary>
        /// <returns></returns>
        public static EnpotIPAddressModel GetIPAddressAdv()
        {
            string arg_Ip = IPAddressUtils.GetRequestIP();

            if (!IPAddressUtils.IsIP(arg_Ip))
            {
                throw new Exception("错误:无效IP信息。");
            }

            List <EnpotIPAddressModel> all = new List <EnpotIPAddressModel>();

            all.Add(IPAddressUtils.SinaGetIPAddress(arg_Ip));
            //all.Add(IPAddressUtils.BaiduGetIPAddress(arg_Ip));
            //all.Add(IPAddressUtils.TaobaoGetIPAddress(arg_Ip));

            EnpotIPAddressModel result = IPAddressUtils.SelectAddress(arg_Ip, all);

            result.Device = IPAddressUtils.GetUserAgent();
            return(result);
        }