当前位置 : 主页 > 编程语言 > python >

获取ip地址归属地

来源:互联网 收集:自由互联 发布时间:2022-10-26
免费版,每个月限制只能获取30000 import requests def get_ip(): response = requests.get('https://api64.ipify.org?format=json').json() return response["ip"] def get_location(): ip_address = get_ip() response = requests.get('https:

免费版,每个月限制只能获取30000

import requests


def get_ip():
response = requests.get('https://api64.ipify.org?format=json').json()
return response["ip"]


def get_location():
ip_address = get_ip()

response = requests.get('https://ipapi.co/{}/json/'.format(ip_address)).json()
location_data = {
"ip": ip_address,
"city": response.get("city"),
"region": response.get("region"),
"country": response.get("country_name")
}
return location_data


print(get_location())
上一篇:代码加密
下一篇:没有了
网友评论