MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / get_my_ip

Function get_my_ip

web/pgadmin/misc/cloud/utils/__init__.py:20–41  ·  view source on GitHub ↗

Return the public IP of this host

()

Source from the content-addressed store, hash-verified

18
19
20def get_my_ip():
21 """ Return the public IP of this host """
22 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
23 http = urllib3.PoolManager(cert_reqs='CERT_NONE')
24 try:
25 external_ip = http.request('GET', 'https://ifconfig.me/ip').data
26 except Exception:
27 try:
28 external_ip = http.request('GET', 'https://ident.me').data
29 except Exception:
30 external_ip = '127.0.0.1'
31
32 if isinstance(external_ip, bytes):
33 external_ip = external_ip.decode('utf-8')
34
35 ip = ipaddress.ip_address(external_ip)
36 if isinstance(ip, ipaddress.IPv4Address):
37 return IP_ADDRESS_STRING.format(external_ip, 32)
38 elif isinstance(ip, ipaddress.IPv6Address):
39 return IP_ADDRESS_STRING.format(external_ip, 128)
40
41 return IP_ADDRESS_STRING.format(external_ip, 32)
42
43
44def _create_server(data):

Callers 1

get_host_ipFunction · 0.90

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected