mirror of
https://github.com/lalanza808/monero.fail.git
synced 2025-08-20 20:48:23 -04:00
store geoip data
This commit is contained in:
parent
9a25c2e7d0
commit
fae6ab3688
3 changed files with 28 additions and 4 deletions
|
@ -3,7 +3,9 @@ import socket
|
|||
import pickle
|
||||
from os import path
|
||||
|
||||
import geoip2.database
|
||||
from requests import get as r_get
|
||||
from urllib.parse import urlparse
|
||||
from levin.section import Section
|
||||
from levin.bucket import Bucket
|
||||
from levin.ctypes import *
|
||||
|
@ -157,3 +159,11 @@ def get_highest_block(nettype, crypto):
|
|||
return highest.last_height
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def get_geoip(ip_or_dns):
|
||||
host = urlparse(ip_or_dns).netloc.split(':')[0]
|
||||
resolved = socket.gethostbyname(host)
|
||||
host = host if resolved == host else resolved
|
||||
with geoip2.database.Reader("./data/GeoLite2-City.mmdb") as reader:
|
||||
return reader.city(host)
|
Loading…
Add table
Add a link
Reference in a new issue