Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The specific address can be found in the computer according to the ip address.

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the computer according to the ip address can find the specific address, the article is very detailed, has a certain reference value, interested friends must read it!

The specific address can be found according to the ip address; the ip address is an "ID card" obtained according to the network connection point of each computer, and querying the ip address allows us to effectively know where the computer is located.

The ip address is an "ID card" based on the network connection point of each computer. Querying the ip address allows us to effectively know where the computer is located.

The method of querying specific geographical location according to IP address

Baidu map has API for querying addresses according to IP

Http://lbsyun.baidu.com/index.php?title=webapi/ip-api

1. Look up the address directly by IP according to Baidu map API

According to API, the following two addresses can be obtained according to IP:

The request parameters are as follows:

If our request ip is 192.168.1.1, the request address is constructed as follows:

Http://api.map.baidu.com/location/ip?ak=XXX( applied for API TOKEN) & ip=192.168.1.1

Python is used as the experimental language here, and the code and comments are as follows:

From urllib import requestimport json# ak is bound with ipbaidu_api_ak = "ZX9QCmwzzItzRO5ssD7GNgEwD4OQduWR" ip_addr = "xxx.xxx.xxx.xxx" # Request urlurl = "http://api.map.baidu.com/location/ip?ak=" + baidu_api_ak +" & ip= "+ ip_addrreq = request.Request (url) res = request.urlopen (req) res = res.read () # Bytes to strn = res.decode (encoding='utf-8') # str to jsons = json.loads (n) t = json.dumps (s Ensure_ascii=False) print (n) print (t)

The above code roughly means that url is asked to read the returned stream and convert it to json format. The result is shown in the following figure:

Note that in the picture above, you can only see that Chengdu, Sichuan Province, is a large area, and the fields such as "street" are empty. In other words, only a rough range can be found.

PS: there are also latitudes and longitudes in the returned values, but according to the original document, these latitudes and longitudes are the latitudes and longitudes of the city center where IP is located.

2. Check the longitude and latitude first, and look up the address according to the longitude and latitude.

According to the latitude and longitude of IP, Baidu map does not give API, but there are still resources outside the wall. If it's not posted here, go and find it yourself.

If you get the latitude and longitude, you can query the detailed address through the latitude and longitude + Baidu map API.

The global reverse address code API of Baidu Maps is as follows:

Http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding-abroad

As shown in the figure below, assuming that we have obtained the latitude and longitude, according to the rules on API, the location parameter is followed by the latitude and longitude. According to the latitude and longitude, we can find out the detailed address.

The experimental code and notes are as follows:

#! / usr/bin/env python# coding=utf-8from urllib import requestimport json# ak is bound with ipbaidu_api_ak = "ZX9QCmwzzItzRO5ssD7GNgEwD4OQduWR" url = "http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=30.6667,104.0670&output=json&pois=1&ak=" + baidu_api_akreq = request.Request (url) res = request.urlopen (req) res = res.read () n = res.decode (encoding='utf-8') # The result format is renderReverse&&renderReverse (json str). So....n = n [len ("renderReverse&&renderReverse") + 1 st = json.loads (n) # st's structure# result: XXXX# status: XXXXresult = st ["result"] for i in result: print (I, result [I])

The results are as follows:

The address here is already very detailed, but there is no detailed resolution, which looks a bit messy. To get the specified location information, you can refer to API.

However, usually the results of this query are not correct, perhaps because the operator is confidential to the users, the address found may be the address of the operator server, the specific is what has not been studied.

The above is all the contents of this article "the specific address can be found according to the ip address in the computer". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report