You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Admin.Core.Common
|
|
{
|
|
public static class AddressHelper
|
|
{
|
|
// IP地址查询
|
|
public const string IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
|
|
|
|
// 未知地址
|
|
public const string UNKNOWN = "XX XX";
|
|
|
|
public static string GetRealAddressByIP(string ip)
|
|
{
|
|
string address = UNKNOWN;
|
|
// 内网不查询
|
|
if (IpHelper.InternalIp(ip))
|
|
{
|
|
return "内网IP";
|
|
}
|
|
try
|
|
{
|
|
string rspStr = HttpHelper.Get(IP_URL + "?ip=" + ip + "&json=true");
|
|
if (rspStr.IsNotEmptyOrNull())
|
|
{
|
|
//log.error("获取地理位置异常 {}", ip);
|
|
return UNKNOWN;
|
|
}
|
|
var obj = JsonHelper.ParseFormByJson<object>(rspStr);
|
|
//string region = obj.ObjToDecimal["pro"];
|
|
//string city = obj.getString("city");
|
|
//return string.Format("{0} {1}", region, city);
|
|
return null;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//log.error("获取地理位置异常 {}", ip);
|
|
}
|
|
|
|
return address;
|
|
}
|
|
}
|
|
|
|
}
|