Tool recommendation - precise positioning of latitude and longitude based on IP address (permanent free)

Today, Xiao Zhang needs to accurately locate the user's country, city, longitude, latitude and other information according to the user's access ip, search from the Internet, and find many websites, but there are almost no fully compliant ones, and some of them need to spend money. As you know, now is the era of information sharing, is there really no free API interface to call?

Continue to search, and finally work hard to win the hearts of people. Find it, it is it, it is it. Don't worry. Look at the code first.

 

import requests,traceback,logging,random
from retry import retry


user_agent_list = [
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 "
    "(KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
    "Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 "
    "(KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 "
    "(KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6",
    "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 "
    "(KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6",
    "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 "
    "(KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1",
    "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 "
    "(KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5",
    "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 "
    "(KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
    "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3",
    "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3",
    "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 "
    "(KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3",
]
headers = {
'Connection': 'close',
"User-Agent": random.choice(user_agent_list)
}
#Query country according to ip
@retry(Exception, tries=2, delay=6)
def ip_map(ip):
        url=f"http://ip-api.com/json/{ip}?fields=61439&lang=zh-CN"  
        response=requests.get(url=url,headers=headers,timeout=5).json()
        print(response)


if __name__ == '__main__':
    try:
        ip_map("212.32.35.64")
    except:
        val = traceback.format_exc()
        logging.error("The error location information is>>>%s" % val)

 

The results are as follows:

{
    'status': 'success',
    'country': 'Britain',
    'countryCode': 'GB',
    'region': 'WLS',
    'regionName': 'Wales',
    'city': 'Radyr',
    'zip': 'CF15 8EN',
    'lat': 51.5318,
    'lon': -3.25879,
    'timezone': 'Europe/London',
    'isp': 'MISTRAL',
    'org': 'Frontier  Limited',
    'as': 'AS8897 KCOM Group Public Limited Company',
    'query': '212.32.35.64'
}

The specific code can't be explained. So you can read the introduction of their official website first

Xiao Zhang will translate for you (in fact, the translation function of Google browser is used):

How powerful is it.

For specific official API documents, you can scan the QR code in the upper right corner and reply to IP after paying attention to obtain detailed documents.

Tags: Python Windows JSON Linux Google

Posted on Thu, 02 Apr 2020 20:08:55 -0700 by bigscanner