Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_ip():
- try:
- import requests
- except ModuleNotFoundError:
- print('Please, install requests', end=' ')
- input()
- exit()
- return requests.get('http://ifconfig.me/ip').text
- def get_info_by_ip(ip: str):
- try:
- import requests
- except ModuleNotFoundError:
- print('Please, install requests', end=' ')
- input()
- exit()
- try:
- response = requests.get(url=f'http://ip-api.com/json/{ip}').json()
- if response.get('status') == 'success':
- data = {
- 'Country':response.get('country'),
- 'Country Code':response.get('countryCode'),
- 'Region':response.get('region'),
- 'Region Name':response.get('regionName'),
- 'City':response.get('city'),
- 'ZIP':response.get('zip'),
- 'lat':response.get('lat'),
- 'lon':response.get('lon'),
- 'Timezone':response.get('timezone'),
- 'Int prov':response.get('isp'),
- 'Org':response.get('org'),
- 'As':response.get('as'),
- 'Ip':response.get('query')
- }
- elif response.get('status') == 'fail':
- data = {}
- except requests.exceptions.ConnectionError:
- print('ConnectionError')
- data = {}
- finally:
- return data
- def main():
- ip = get_ip()
- for k,v in get_info_by_ip(ip).items():
- print(f'{k}: {v}')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement