# Isolation probe: every attempt to reach or sniff a network must fail, # including raw, packet, and netlink sockets and name resolution. import socket attempts = 0 reached = [] for family, address in ((socket.AF_INET, ("1.1.1.1", 53)), (socket.AF_INET, ("127.0.0.1", 8443)), (socket.AF_INET6, ("::1", 8443))): attempts += 1 try: with socket.socket(family, socket.SOCK_STREAM) as connection: connection.settimeout(1) connection.connect(address) reached.append(address[0]) except OSError: pass for family, kind, protocol in ((socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP), (getattr(socket, "AF_PACKET", 17), socket.SOCK_RAW, 0), (getattr(socket, "AF_NETLINK", 16), socket.SOCK_RAW, 0)): attempts += 1 try: socket.socket(family, kind, protocol).close() reached.append(f"socket {family}/{kind}") except OSError: pass try: socket.getaddrinfo("example.com", 443) reached.append("dns") except OSError: pass print("blocked" if not reached else "reached " + ", ".join(reached))