. NET (C #) calls webService to obtain the region of the Client IP address (non-asynchronous ),

Source: Internet
Author: User

. NET (C #) calls webService to obtain the region of the Client IP address (non-asynchronous ),

Function Description:

This interface is used to obtain the region (country, city, etc.) of the IP address accessed by the client ). Enter an IP address to query country, city, owner, and other information. If the country is not specified, enter the China parameter: IP address (automatically replaced ". "Is ". "), return data: A one-dimensional String array String (1), String (0) = IP address; String (1) = country, city, owner, etc. 1.1.1. interface address Webservice method: for example: http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp 1.1.2. method Name getCountryCityByIp 1.1.3. parameter description request parameter: parameter name Chinese meaning type required remarks No 32-bit binary number String is for example: "127.0.0.1" No 32-bit binary number String is for example: "218.108.242.108" return result: parameter name Chinese meaning type required remarks string [] strArea_IP return array containing IP information String [] No example: Count = 2, the array length is 2 () strArea_IP [0] IP Address requested by the client String no For example: "218.108.242.108" strArea_IP [1] region information of the IP address String no For example: the "Hangzhou, Zhejiang" area is obtained through the input IP Parameters: According to the third-party website (webservice provider), by capturing the IP address of the computer on this website Obtain the region of the client's IP address. Of course, if this website has changed its domain name or does not exist that day, this method will not work properly! The next thing is very simple. Add the preceding webservice to the project, and then call this webservice to obtain the Internet access area. The code is implemented as follows: /// <summary> /// region where the Internet IP address is located /// </summary> /// <returns> </returns> private string GetConnectNetAddressArea () {string strIP = "218.108.242.108; // The requested IP address IpAddressSearchWebService webService = new IpAddressSearchWebService (); string [] strArea_IP = webService. getCountryCityByIp (strIP); return strArea_IP [1]; // return result: "Hangzhou, Zhejiang Province"} copy the code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.