-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_scanner.py
52 lines (31 loc) · 985 Bytes
/
port_scanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import threading, socket, sys
import tld # Top Level Domain
from queue import Queue
user_inputs = sys.argv # It's a LIST of STRING
print_lock = threading.Lock()
# Can be a Domain name or IP Address
# Note: user_inputs[0] it's a script's path so you don't need it
target = user_inputs[1]
q = Queue()
def portscan(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
con = s.connect((target, port))
with print_lock:
print('Port ', port, ' is Open!!!!!!!!')
con.close()
except:
pass
for port in range(int(user_inputs[2]), int(user_inputs[3])):
q.put(port)
def threader():
while True:
getting_port = q.get()
portscan(getting_port)
q.task_done()
for x in range(int(user_inputs[4])-1):
t = threading.Thread(target=threader, args=())
t.daemon = True
t.start()
print("\n******** You have ", threading.active_count(), "Running threads ***********\n")
q.join()