. 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 ". "."), 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:

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

Meaning

Type

Required

Remarks

None

32-bit binary

String

Yes

Example: "127.0.0.1"

None

 

32-bit binary String Yes Example: "218.108.242.108"
Returned results:

Parameter Name

Meaning

Type

Required

Remarks

String [] strArea_IP

Returns an array containing IP information.

String []

No

For example, Count = 2 indicates that the array length is 2 (0, 1)

StrArea_IP [0]

IP Address requested by the client

String

No

Example: "218.108.242.108"

StrArea_IP [1]

Region information of the IP address

String

No

For example, "Zhejiang and Hangzhou"

         

The following figure shows the region of an IP address:

Based on a third-party website (webservice provider), you can obtain the region of the client's IP address by capturing the IP address of the computer on this website.

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 "}View Code

 

 


Net is C/S.

The program system is divided into B/S and C/S. C/S indicates the Client/Server, the client is the machine that enjoys the service, and the server is the machine that provides the service.
For example, if you buy breakfast, the breakfast is the server, and the breakfast service is provided. We are the client to enjoy the services provided. The communication between the two parties is initiated by the client.
In a computer, the client is an interface written in C # Or VB. The server is a database and provides data services. The C/S program needs to download the client.
Common C/S programs and QQ games.

What does {0: C} mean in net?

Format characters when the output content is used. {n} represents a placeholder. For example, {0} indicates that the output position is replaced by the first parameter. C is the specific formatting control information, for example, the currency information to be output.
Where:
C | C: currency format
D | D: represents the decimal format
E | E: representing the scientific count (INDEX) Format
F | F: Floating Point format
X | X: hexadecimal format.

In addition, this output method is used in the C # language, and. net is a development platform.

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.