I wrote an article in front of "C # Network programming to get the native name, IP address, domain name, physical location" can be based on the input of the URL based on its IP address acquisition of physical location, which is the main code through the Youdao network provided by the online Third-party interface to achieve dynamic access to its data. "Reference popping _dancer's blog code, whose main code is shown in the following illustration:
///<summary>///Physical address based on IP///</summary>///<param name= "StrIP" ></param >///<returns></returns> public static string getstringipaddress (String StrIP)//strip to IP {string SUR
L = "http://www.youdao.com/smartresult-xml/search.s?type=ip&q=" + StrIP + ""; String stringipaddress = ""; Geographical using (XmlReader read = Xmlreader.create (sURL))//Get Youdao returned XML format file content {while read. Read ())//reads the next byte from the stream {switch (read. NodeType) {case XmlNodeType.Text://Fetch text content in XML format file if (str Ing. Format (' {0} ', read. Value). ToString (). Trim ()!= StrIP) {stringipaddress=string. Format (' {0} ', read. Value). ToString ().
Trim ();
} break;
}} return stringipaddress; }
The results obtained at that time are shown in the following figure, but may be due to the way the URL has been deleted, and now it is no longer possible to obtain a geographic location through the interface. All I have offered a new way to help everyone and that friend.
Because of its limited capacity, it will only get physical addresses through access to Third-party interfaces, and depends largely on the library data provided by the Web site, and it would not be appropriate to use a local static library to find the appropriate geographic location. The Web site currently visited is: http://www.freegeoip.net/xml/
The source code and the results shown are as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks; Using System.Xml; XML Document namespace GetLocation {class Program {static void Main (string[] args) {str ing StrIP = "74.125.31.104"; IP address string strurl = "http://www.freegeoip.net/xml/" + StrIP; URL string Location = ""; Physical location//through getElementsByTagName get tag node set XmlDocument doc = new XmlDocument (); XML document Doc. Load (strURL); Load strURL Specify XML data XmlNodeList nodelstcity = doc. getElementsByTagName ("City"); Get the label Location = "Get a single physical location:" + nodelstcity[0].
InnerText + "";
Console.WriteLine (Location); Match the first node XmlNode root = Doc by selectSingleNode match.
selectSingleNode ("Response"); if (root != null) {string countryname = (root. selectSingleNode ("CountryName")).
InnerText; String regionname = (root. selectSingleNode ("Regionname")).
InnerText; String city = (root. selectSingleNode ("City")).
InnerText;
location= "Country name:" +countryname+ "\ n Region name:" +regionname+ "\ n City Name:" +city;
Console.WriteLine (Location);
} console.read (); }
}
}
This paper obtains the tag tag in XML document by getElementsByTagName and selectSingleNode two methods to obtain http://www.freegeoip.net/xml/ The physical location in the www.baidu.com. We recommend learning C # to read XML files to develop the knowledge of the node. The results of the operation are shown in the following illustration:
Here are some of these very good content for everyone to learn, but also convenient for their next check:
1.c# network programming to get the local name \IP address \ Domain \ Physical location (this is my own article, combined with this article to learn)
http://blog.csdn.net/eastmount/article/details/9270221
2.Get user Location by IP address (using C # to obtain physical location is also the basis of this article)
Http://www.codeproject.com/Questions/686644/Get-user-location-by-IP-address
3. Get the computer physical address and access to the current location via IP address-a column for street food (using PHP to get very good articles)
http://blog.csdn.net/lzwjavaphp/article/details/6972667
4.IP address Location in asp.net (consume a free online APIs and fetch data using LINQ to XML)
http://www.dotnetcurry.com/showarticle.aspx?ID=325
5.get uesr location by IP address (discussion about it hope everyone goes to stack overflow learning knowledge)
Http://stackoverflow.com/questions/4327629/get-user-location-by-ip-address
6.xmldocument.load (URL) question (read the weather information article, same as My method)
Http://www.cnblogs.com/sharpfeng/archive/2011/03/02/1968666.html
Finally hope that this article is helpful to everyone, and hope that the article can help the classmate to solve the problem. If the article is wrong or deficient, forgive me! Since only this method of obtaining physical location through a Third-party interface is relied upon to a large extent by the data of third parties, if the URL is abolished, it is cumbersome, At the same time will encounter different Web site query results are also different. I hope there is a good way to talk about sharing.
(By:eastmount 2014-1-22 5 o'clock in the afternoon http://blog.csdn.net/eastmount)