33 lines
990 B
Python
33 lines
990 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright Grégory Soutadé 2022
|
|
|
|
# This file is part of iwla
|
|
|
|
# iwla is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# iwla is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
import urllib3
|
|
import json
|
|
|
|
def geoiplookup(ip):
|
|
http = urllib3.PoolManager()
|
|
r = http.request('GET', f'https://api.geoiplookup.net/?query={ip}&json=true')
|
|
|
|
if r.status != 200:
|
|
raise Exception(r)
|
|
|
|
return json.loads(r.data.decode('utf-8'))
|