Skip to content

Commit e09e0e5

Browse files
committed
added colors to port scanner
1 parent 6d4dc8b commit e09e0e5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

ethical-hacking/port_scanner/fast_port_scanner.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import argparse
22
import socket # for connecting
3+
from colorama import init, Fore
34

4-
from threading import Thread
5+
from threading import Thread, Lock
56
from queue import Queue
67

8+
# some colors
9+
init()
10+
GREEN = Fore.GREEN
11+
RESET = Fore.RESET
12+
GRAY = Fore.LIGHTBLACK_EX
13+
714
# number of threads, feel free to tune this parameter as you wish
815
N_THREADS = 200
916
# thread queue
1017
q = Queue()
18+
print_lock = Lock()
1119

1220
def port_scan(port):
1321
"""
@@ -17,9 +25,11 @@ def port_scan(port):
1725
s = socket.socket()
1826
s.connect((host, port))
1927
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')
2130
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}")
2333
finally:
2434
s.close()
2535

ethical-hacking/port_scanner/simple_port_scanner.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
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
29

310
def is_port_open(host, port):
411
"""
@@ -10,7 +17,7 @@ def is_port_open(host, port):
1017
# tries to connect to host using that port
1118
s.connect((host, port))
1219
# make timeout if you want it a little faster ( less accuracy )
13-
# s.settimeout(0.2)
20+
s.settimeout(0.2)
1421
except:
1522
# cannot connect, port is closed
1623
# return false
@@ -24,6 +31,6 @@ def is_port_open(host, port):
2431
# iterate over ports, from 1 to 1024
2532
for port in range(1, 1025):
2633
if is_port_open(host, port):
27-
print(f"[+] {host}:{port} is open ")
34+
print(f"{GREEN}[+] {host}:{port} is open {RESET}")
2835
else:
29-
print(f"[!] {host}:{port} is closed ", end="\r")
36+
print(f"{GRAY}[!] {host}:{port} is closed {RESET}", end="\r")

0 commit comments

Comments
 (0)