. NET (C #) Call WebService get client IP address zone (non-async)

Source: Internet
Author: User

  Function Description:

This interface is used to obtain the IP address to which the client accesses the region (country, city, etc.). Query the country, city, owner and other information by entering the IP address. No country specified for China input parameter: IP address (auto replace). "For". " ), return data: A one-dimensional string array of string (1), string (0) = IP address; string (1) = country, city, owner, etc.

1.1.1. Interface Address

WebService Way:

Example: Http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp

1.1.2. Method Name

Getcountrycitybyip

1.1.3. Parameter Description Request Parameters:

Parameter name

Chinese meaning

Type

Must fill in

Note

No

32 bits binary number

String

Is

For example: "127.0.0.1"

No

32 bits binary number String Is For example: "218.108.242.108"
return Result:

Parameter name

Chinese meaning

Type

Must fill in

Note

String[] Strarea_ip

Returns an array that contains IP information

String []

Whether

For example: count=2, which indicates an array length of 2 (0,1)

STRAREA_IP[0]

IP address requested by the client

String

Whether

For example: "218.108.242.108"

STRAREA_IP[1]

IP Address Region information

String

Whether

For example: "Hangzhou, Zhejiang"

The following is the IP parameter passed in to obtain the owning zone:

According to the third party website (WebService provider), by crawling the Internet IP address of the computer on this website to obtain the IP address of the client to the region.

Of course, if that day this site changed the domain name or does not exist, this method will not be used properly Oh!

The next thing is very simple, add the above webservice to the project, and then call this webservice to get the area of the Internet.

The code is specifically implemented as follows:

        /// <summary>        ///get the area of the Internet IP/// </summary>        /// <returns></returns>        Private stringGetconnectnetaddressarea () {stringStrIP = "218.108.242.108;//the requested IP addressIpaddresssearchwebservice WebService=NewIpaddresssearchwebservice (); string[] strarea_ip=Webservice.getcountrycitybyip (StrIP); returnstrarea_ip[1];//return Result: "Hangzhou, Zhejiang"}
View Code

. NET (C #) Call WebService get client IP address zone (non-async)

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.