(Dec-02-2020, 04:02 AM)erdravi Wrote: Thanks. How to differentiate, whether the site is accessible by internet or intranet?
In this case, the first step is to resolve the IP Address.
from ipaddress import ip_address
from urllib.parse import urlparse
from socket import gethostbyname
# get the hostname
url = "https://python-forum.io"
host = urlparse(url).hostname
print(host)
# resolve the ip address
ip = gethostbyname(host)
print(ip)
# converting the str into a IPv4Address object
ip = ip_address(ip)
print(ip)
# IPv4Address has the property is_private
if ip.is_private:
print(url, "is a target in a private network")
else:
print(url, "is a target in the internet")