Skip to content

Instantly share code, notes, and snippets.

@tuhin47
Created July 16, 2023 15:03
Show Gist options
  • Save tuhin47/fe95fa4f51c10d50e3d10ab51538eccd to your computer and use it in GitHub Desktop.
Save tuhin47/fe95fa4f51c10d50e3d10ab51538eccd to your computer and use it in GitHub Desktop.
Find Dynamic Public IP in my router
import socket
import concurrent.futures
def ping_ip_port(ip, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect((ip, port))
print("http://{}:{}".format(ip,port))
return True
except Exception:
return False
# TODO Update port and ip pattern
port_number = 8080
ip_format="127.0.0.{0}"
executor = concurrent.futures.ThreadPoolExecutor(max_workers=255)
futures = []
for ip_int in range(0, 255 + 1):
ip=ip_format.format(ip_int)
future = executor.submit(ping_ip_port, ip, port_number)
futures.append(future)
for future in concurrent.futures.as_completed(futures):
future.result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment