File tree 2 files changed +23
-6
lines changed
ethical-hacking/port_scanner
2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 1
1
import argparse
2
2
import socket # for connecting
3
+ from colorama import init , Fore
3
4
4
- from threading import Thread
5
+ from threading import Thread , Lock
5
6
from queue import Queue
6
7
8
+ # some colors
9
+ init ()
10
+ GREEN = Fore .GREEN
11
+ RESET = Fore .RESET
12
+ GRAY = Fore .LIGHTBLACK_EX
13
+
7
14
# number of threads, feel free to tune this parameter as you wish
8
15
N_THREADS = 200
9
16
# thread queue
10
17
q = Queue ()
18
+ print_lock = Lock ()
11
19
12
20
def port_scan (port ):
13
21
"""
@@ -17,9 +25,11 @@ def port_scan(port):
17
25
s = socket .socket ()
18
26
s .connect ((host , port ))
19
27
except :
20
- print (f"{ host :15} :{ port :5} is closed " , end = '\r ' )
28
+ with print_lock :
29
+ print (f"{ GRAY } { host :15} :{ port :5} is closed { RESET } " , end = '\r ' )
21
30
else :
22
- print (f"{ host :15} :{ port :5} is open " )
31
+ with print_lock :
32
+ print (f"{ GREEN } { host :15} :{ port :5} is open { RESET } " )
23
33
finally :
24
34
s .close ()
25
35
Original file line number Diff line number Diff line change 1
1
import socket # for connecting
2
+ from colorama import init , Fore
3
+
4
+ # some colors
5
+ init ()
6
+ GREEN = Fore .GREEN
7
+ RESET = Fore .RESET
8
+ GRAY = Fore .LIGHTBLACK_EX
2
9
3
10
def is_port_open (host , port ):
4
11
"""
@@ -10,7 +17,7 @@ def is_port_open(host, port):
10
17
# tries to connect to host using that port
11
18
s .connect ((host , port ))
12
19
# make timeout if you want it a little faster ( less accuracy )
13
- # s.settimeout(0.2)
20
+ s .settimeout (0.2 )
14
21
except :
15
22
# cannot connect, port is closed
16
23
# return false
@@ -24,6 +31,6 @@ def is_port_open(host, port):
24
31
# iterate over ports, from 1 to 1024
25
32
for port in range (1 , 1025 ):
26
33
if is_port_open (host , port ):
27
- print (f"[+] { host } :{ port } is open " )
34
+ print (f"{ GREEN } [+] { host } :{ port } is open { RESET } " )
28
35
else :
29
- print (f"[!] { host } :{ port } is closed " , end = "\r " )
36
+ print (f"{ GRAY } [!] { host } :{ port } is closed { RESET } " , end = "\r " )
You can’t perform that action at this time.
0 commit comments