[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: geo.py
File is not writable. Editing disabled.
from contextlib import contextmanager from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network from typing import Union import geoip2.database from geoip2.errors import AddressNotFoundError from defence360agent.contracts.config import CountryInfo from im360.utils.validate import IP class Reader: def __init__(self, geoip2_reader): self._geoip2_reader = geoip2_reader def get(self, address: Union[str, IPv4Address, IPv4Network, IPv6Address, IPv6Network]): """ Returns geo country information from max mind's db request :param address: ip or network address e.g. '4.4.4.4, 1.2.0.0/16, 2001:678:4c::/48' :return: maxmind's geo info """ try: ip = IP.adopt_to_ipvX_network(address) except ValueError: return None try: obj = self._geoip2_reader.country(str(ip.network_address)) except AddressNotFoundError: return None # According to documentation: # https://geoip2.readthedocs.io/en/latest/#what-data-is-returned # (...) MaxMind does not always have every piece of data for any given # IP address. Because of these factors, it is possible for any request # to return a record where some or all of the attributes are # unpopulated. (...) return obj.country if obj else None def get_id(self, address: Union[str, IPv4Address, IPv4Network, IPv6Address, IPv6Network]): """ :param address: valid ipv4 address :return: maxmind's id of the country """ country_info = self.get(address) if country_info: return country_info.geoname_id return None def get_code(self, address: Union[str, IPv4Address, IPv4Network, IPv6Address, IPv6Network]): """ :param address: valid ipv4 address :return: country code in ISO-3166 format """ country_info = self.get(address) if country_info: return country_info.iso_code return None @contextmanager def reader(): """ :return Reader obj: instance to be reused to it's method calls """ with geoip2.database.Reader(CountryInfo.DB) as geoip2_reader: yield Reader(geoip2_reader)
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.07 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A