-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScanner.py
More file actions
46 lines (33 loc) · 1.34 KB
/
Copy pathScanner.py
File metadata and controls
46 lines (33 loc) · 1.34 KB
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
import socket
import time
import sys
def port_checker(socket_ip, start_port, end_port):
print("Start port is:", start_port, "End port is:", end_port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Open socket
for i in range(start_port, end_port):
start_ms_counter = int(round(time.time() * 1000)) # Ping counter start
socket_status = s.connect_ex((socket_ip, i)) # Get the socket port status
# if status is 0 – port is opened, else – port is closed.
if socket_status == 0:
status = "is opened"
else:
status = "is closed"
count_millis = int(round(time.time() * 1000)) - start_ms_counter # Ping counter end
ends = ((end_port - i) * (count_millis/1000)) / 60 # Time's left counter
# Output
output = socket_ip + ", port " + str(i) + " " + status + ", ping: " + str(count_millis)
print(output, end='')
print('\tTime\'s left:', int(ends / 60), 'Hours', int(ends % 60), 'Minutes')
if __name__ == '__main__':
# Software env
ip = "127.0.0.1"
start = 1
end = 65535
# Get user's arguments
if len(sys.argv) >= 2:
ip = str(sys.argv[1])
if len(sys.argv) >= 3:
start = int(sys.argv[2])
if len(sys.argv) == 4:
end = int(sys.argv[3])
port_checker(ip, start, end)