通过ip获取对应的地址信息(新浪查询)
/// <summary>
/// 通过ip获取对应的地址信息(新浪查询)
/// </summary>
/// <param name=\"大众ip\"大众>ip地址</param>
/// <returns></returns>
public static string GetAddressByIPfromSina(string ip)
{
string url = string.Format(@\"大众http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip={0}\公众, ip);
string result = GetRequestResult(url);
return Regex.Unescape(result);
}
2.通过ip获取对应的地址信息(淘宝查询)
/// <summary>
/// 通过ip获取对应的地址信息(淘宝查询)
/// </summary>
/// <param name=\"大众ip\公众>ip地址</param>
/// <returns></returns>
public static string GetAddressByIPfromTaobao(string ip)
{
string url = string.Format(@\"大众http://ip.taobao.com/service/getIpInfo.php?ip={0}\"大众, ip);
string result = GetRequestResult(url);
return Regex.Unescape(result);
}
3.通过ip获取对应的地址信息(百度查询)
/// <summary>
/// 通过ip获取对应的地址信息(百度查询)
/// </summary>
/// <param name=\"大众ip\"大众>ip地址</param>
/// <returns></returns>
public static string GetAddressByIPfromBaidu(string ip)
{
string url = string.Format(@\"大众https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={0}&co=&resource_id=6006&t=1478007629021&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery110206812252158470637_1478007583131&_=1478007583168\"大众, ip);
string result = GetRequestResult(url);
return Regex.Unescape(result);
}
查询方法:
/// <summary>
/// 获取要求url相应
/// </summary>
/// <param name=\"大众url\"大众>url地址</param>
/// <returns></returns>
public static string GetRequestResult(string url)
{
try
{
string responseResult = \"大众\"大众;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader str = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding(\"大众GBK\"大众));
responseResult = str.ReadToEnd();
str.Close();
str.Dispose();
responseStream.Close();
return responseResult;
}
catch (Exception ex)
{
return \公众-1\公众;
}
}
附上共享链接地址:https://1drv.ms/u/s!Ath1PRgsHdpJg1Hybnycn8xttyWo,如果文章还不错,给小编一个一个赞吧,赞下又不会有身的.