Created
December 5, 2023 08:27
-
-
Save sulincix/38abf3873fc2fc566175c1fee2a1736c to your computer and use it in GitHub Desktop.
Port Scan using python
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
#!/usr/bin/env python3 | |
import sys | |
import socket | |
def isReachable(ipOrName, port, timeout=2): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.settimeout(timeout) | |
try: | |
s.connect((ipOrName, int(port))) | |
s.shutdown(socket.SHUT_RDWR) | |
return True | |
except: | |
return False | |
finally: | |
s.close() | |
if len(sys.argv) < 2: | |
print("Usage: scan.py <ip-or-name>") | |
exit(1) | |
ip = sys.argv[1] | |
for i in range(1,1024): | |
if isReachable(ip, str(i)): | |
print("{} {}".format(ip, i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment