Last active
April 30, 2021 20:45
-
-
Save secoats/9c390bbb68b274097c8da0675afb7b3c to your computer and use it in GitHub Desktop.
TCP SYN Scan in Python3
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 | |
# U+0A75 | |
# sudo python3 syn_scan.py 127.0.0.1 | |
import threading | |
from socket import * | |
import sys | |
if len(sys.argv) < 2: | |
print("ip param required") | |
sys.exit(1) | |
target_ip = sys.argv[1] | |
tcp_top20 = [21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, | |
443, 445, 993, 995, 1723, 3306, 3389, 5900, 8080] | |
tcp_full = [*range(65535, 0, -1)] | |
num_threads = 8 | |
ports = tcp_full | |
def worker(): | |
while True: | |
try: | |
port = ports.pop() | |
s = socket(AF_INET, SOCK_STREAM) | |
conn = s.connect_ex((target_ip, port)) | |
if(conn == 0) : | |
print('Port {p:5d} OPEN'.format(p=port)) | |
s.close() | |
except IndexError: | |
break # stop when ports list empty | |
for _ in range(num_threads): | |
threading.Thread(target=worker).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment