Add Geo IP web service function in misc
This commit is contained in:
parent
b92a017dba
commit
0e7b6c9131
1
misc/__init__.py
Normal file
1
misc/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#
|
32
misc/geoiplookup.py
Normal file
32
misc/geoiplookup.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/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'))
|
Loading…
Reference in New Issue
Block a user