Created
December 7, 2021 18:15
-
-
Save bwindsor/079ff2a2b780fb23c98a2490531a52b3 to your computer and use it in GitHub Desktop.
Ping many IP addresses in parallel to see which respond to a ping. Useful for finding IPs of another device you put on the network.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import subprocess | |
def f(x: int) -> None: | |
try: | |
output = subprocess.check_output(["ping", "-n", "1", f"192.168.1.{x}"]) | |
if b"unreachable" not in output: | |
print(f"{x} was successful") | |
except subprocess.CalledProcessError: | |
pass | |
threads = [threading.Thread(target=f, args=(i,)) for i in range(1, 255)] | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment