-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportscanner.py
53 lines (43 loc) · 1.47 KB
/
portscanner.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
import concurrent.futures
import socket
import threading
import datetime
from termcolor import colored
from main import url
start_time = datetime.datetime.now()
# Threading - We can Perform multiple task simultaneously
print_lock = threading.Lock()
print("\n")
print(colored("Port Scanning Process", 'red'))
print("\n")
# Take input from the user
server = (url)
ip = socket.gethostbyname(server)
print("The ip address of host is", colored(ip, 'green'))
# To print new line
print("\n")
#To print the time when service started.
print("This process will check all the port from 1 to 65,535.\n")
print("The service started at {}".format(start_time.strftime("%c")))
print("\n")
# Pass the ip and port into the function.
def scan_port(ip, port):
# The socket in the Internet domain, and
# configures it for stream-oriented communication with default TCP protocol
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((ip, port))
s.close()
with print_lock:
print('Port', colored(port, 'green'), 'and service', colored(socket.getservbyport(port), 'green'),
' is open')
except:
pass
with concurrent.futures.ThreadPoolExecutor(max_workers=5000) as executor:
for port in range(65535):
executor.submit(scan_port, ip, port + 1)
end_time = datetime.datetime.now()
# To print the time when service ended.
print("\nThe service ended at {}".format(end_time.strftime("%c")))
print("\n")