C#應用有道ip地址查詢接口辦法實例詳解。本站提示廣大學習愛好者:(C#應用有道ip地址查詢接口辦法實例詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是C#應用有道ip地址查詢接口辦法實例詳解正文
本文實例講述了C#應用有道ip地址查詢接口辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
#region 讀取http://www.yodao.com接口IP地址
/// <summary>
/// 讀取http://www.yodao.com接口IP地址
/// </summary>
public static string GetstringIpAddress(string strIP)//strIP為IP
{
string sURL = "http://www.youdao.com/smartresult-xml/search.s?type=ip&q="+strIP+"";
//youdao的URL
string stringIpAddress = "";
using (XmlReader read = XmlReader.Create(sURL))
//獲得youdao前往的xml格局文件內容
{
while (read.Read())
{
switch (read.NodeType)
{
case XmlNodeType.Text://取xml格局文件傍邊的文本內容
if (string.Format("{0}", read.Value).ToString().Trim() != strIP)
//youdao前往的xml格局文件內容一個是IP,
//另外一個是IP地址,假如不是IP那末就是IP地址
{
stringIpAddress=string.Format("{0}", read.Value).ToString().Trim();//賦值
}
break;
//other
}
}
}
return stringIpAddress;
}
前往的xml數據格局:
<?xml version="1.0" encoding="gbk" ?> <smartresult> <product type="ip"> <ip>60.223.233.226</ip> <location>山西省朔州市 網通</location> </product> </smartresult>
願望本文所述對年夜家的C#法式設計有所贊助。