Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite09e0e5

Browse files
committed
added colors to port scanner
1 parent6d4dc8b commite09e0e5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

‎ethical-hacking/port_scanner/fast_port_scanner.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
importargparse
22
importsocket# for connecting
3+
fromcoloramaimportinit,Fore
34

4-
fromthreadingimportThread
5+
fromthreadingimportThread,Lock
56
fromqueueimportQueue
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
defport_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+
withprint_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+
withprint_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‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
importsocket# for connecting
2+
fromcoloramaimportinit,Fore
3+
4+
# some colors
5+
init()
6+
GREEN=Fore.GREEN
7+
RESET=Fore.RESET
8+
GRAY=Fore.LIGHTBLACK_EX
29

310
defis_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
forportinrange(1,1025):
2633
ifis_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)

[8]ページ先頭

©2009-2025 Movatter.jp