/
portex.py
125 lines (89 loc) · 3.42 KB
/
portex.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# !/usr/bin/env python3
##########thelinuxuxer-choice#################
#############subodha prabash ##########
###########port scanner ######
# importing the necessary packages
import time
import sys
import os
# clear
def clear_sc():
# for windows OS
if os.name == "nt":
os.system("cls")
# for linux / Mac OS
else:
os.system("clear")
clear_sc()
#####end loding######
# colored text and background
def prRed(skk): print("\033[91m {}\033[00m".format(skk))
def prGreen(skk): print("\033[92m {}\033[00m".format(skk))
def prYellow(skk): print("\033[93m {}\033[00m".format(skk))
def prLightPurple(skk): print("\033[94m {}\033[00m".format(skk))
def prPurple(skk): print("\033[95m {}\033[00m".format(skk))
def prCyan(skk): print("\033[96m {}\033[00m".format(skk))
def prLightGray(skk): print("\033[97m {}\033[00m".format(skk))
def prBlack(skk): print("\033[98m {}\033[00m".format(skk))
import socket
import time
import concurrent.futures
import sys
if len(sys.argv) == 1:
print(f'\nUsage: "python3 portex.py <IP>"\n(Use "-h" option for more info)')
sys.exit()
if '-h' in sys.argv or '--help' in sys.argv:
print('''
Example usage: python3 portex.py 192.168.234.234 -p 1-1000
-h To show this message
-p(optional) The range of ports to scan. (default: 1-65535)''')
sys.exit()
min_range, max_range = 1, 65535
ip = sys.argv[1]
if '-p' in sys.argv:
min_range, max_range = sys.argv[sys.argv.index('-p') + 1].split('-')
banner = '''
+-------------------------------------------------+
| _ |
| / \ |
| /|oo \ | P O R T E X | I P | |
| (_| /_) |
| _`@/_ \ _ | S C A N N E R | |
| | | \ \\ |
| | (*) | \ )) Secret, XX, LK |
| ______ |__U__| / \// |
| / FIDO \ _//|| _\ / FidoNet 1:617/1337 |
| (________) (_/(_|(____/ |
| (SL) |
+-------------------------------------------------+
=[ PORTEX v1.0.0.1-dev-subodhaprabash-taj0023 ]
+ -- -- =[ A Multi-Threaded Port-Scanner in python3 ]
Portex tip: Example : python3 portex.py www.example.com -p 1-1000
'''
prCyan(banner)
def scanner(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
try:
s.connect((ip, port))
print(f"Port {str(port).ljust(4)} OPEN {socket.getservbyport(port, 'tcp')}")
except socket.timeout:
s.close()
def main():
prGreen("─" * 40)
print(f"Scanning {str(int(max_range) + 1 - int(min_range))} ports in {ip}")
prGreen("─" * 40)
print("PORT STATE SERVICE")
start = time.perf_counter()
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
results = [executor.submit(scanner, i) for i in range(int(min_range), int(max_range) + 1)]
for f in concurrent.futures.as_completed(results):
f.result()
end = time.perf_counter()
prGreen("─" * 40)
print(f"Scanning Took {round(end - start, 2)}s")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit()