Files
lincodex/runner/testdata/hostile/python/network_probe.py
T

19 lines
555 B
Python

# Isolation probe: every attempt to reach a network must fail.
import socket
attempts = [
(socket.AF_INET, ("1.1.1.1", 53)),
(socket.AF_INET, ("127.0.0.1", 8080)),
(socket.AF_INET6, ("::1", 8080)),
]
reached = []
for family, address in attempts:
try:
with socket.socket(family, socket.SOCK_STREAM) as connection:
connection.settimeout(1)
connection.connect(address)
reached.append(address[0])
except OSError:
pass
print("blocked" if not reached else "reached " + " ".join(reached))