This article describes the C# using Youdao IP address query interface method. Share it for your reference. The specific implementation method is as follows:
#region Read interface IP address/// <summary> /// Read the interface IP address/// </summary> public static string GetstringIpAddress(string strIP)//strIP is IP{ string sURL = "/smartresult-xml/?type=ip&q="+strIP+""; //youdao's URL string stringIpAddress = ""; using (XmlReader read = (sURL)) //Get the xml format file content returned by youdao { while (()) { switch () { case ://Get the text content in the xml format file if (("{0}", ).ToString().Trim() != strIP) //One of the xml format file contents returned by youdao is IP. //The other is the IP address. If it is not an IP, then it is the IP address { stringIpAddress=("{0}", ).ToString().Trim();//Assignment } break; //other } } } return stringIpAddress; }
The returned xml data format:
<?xml version="1.0" encoding="gbk" ?> <smartresult> <product type="ip"> <ip>60.223.233.226</ip> <location>Shuozhou City, Shanxi Province Netcom</location> </product> </smartresult>
I hope this article will be helpful to everyone's C# programming.