Dec-01-2020, 10:08 AM
Hi
I want to find programmatically, whether a given URL is accessible via internet/intranet.
Thanks.
I want to find programmatically, whether a given URL is accessible via internet/intranet.
Thanks.
URL check
|
Dec-01-2020, 10:08 AM
Hi
I want to find programmatically, whether a given URL is accessible via internet/intranet. Thanks.
Dec-01-2020, 10:38 AM
use requests status
import requests url = "https://python-forum.io" r = requests.get(url) if r.status_code == requests.codes.ok: print("OK")
Dec-02-2020, 04:02 AM
(Dec-01-2020, 10:38 AM)Axel_Erfurt Wrote: use requests status Thanks. How to differentiate, whether the site is accessible by internet or intranet?
Dec-02-2020, 05:19 AM
You can't tell unless you test it from both places. A server is free to respond in different ways to different clients. All you can tell is if it's accessible from your client.
If you know the IP ranges of your intranet, you can see if the hostname resolves to an IP in that range.
Dec-11-2020, 07:19 AM
(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")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians! |
|