MCPcopy Create free account
hub / github.com/Python3WebSpider/ProxyPool / get_country_iso

Function get_country_iso

proxypool/utils/geo.py:15–30  ·  view source on GitHub ↗

look up the ISO country code (e.g. 'CN', 'US') for an ip address :param ip: ip address string :return: uppercase iso code, or None if unknown/unavailable

(ip)

Source from the content-addressed store, hash-verified

13
14
15def get_country_iso(ip):
16 """
17 look up the ISO country code (e.g. 'CN', 'US') for an ip address
18 :param ip: ip address string
19 :return: uppercase iso code, or None if unknown/unavailable
20 """
21 if _reader is None:
22 return None
23 try:
24 record = _reader.get(ip)
25 except Exception:
26 return None
27 if not record:
28 return None
29 country = record.get('country') or record.get('registered_country') or {}
30 return country.get('iso_code')
31
32
33if __name__ == '__main__':

Callers 2

filter_proxies_by_areaFunction · 0.90
geo.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected