-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_scan.py
65 lines (49 loc) · 1.87 KB
/
port_scan.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
import threading
import socket
from colorama import Fore, Style
import os
import time
os.system('cls')
banner = Fore.RED+ r"""
____ _ ____
| _ \ ___ _ __| |_ / ___| ___ __ _ _ __ _ __ ___ _ __
| |_) / _ \| '__| __| \___ \ / __/ _` | '_ \| '_ \ / _ \ '__|
| __/ (_) | | | |_ ___) | (_| (_| | | | | | | | __/ |
|_| \___/|_| \__| |____/ \___\__,_|_| |_|_| |_|\___|_| """
banner2 = Fore.WHITE + """
Version:1.0 - By: @Bernard-Appiah
https://github.com/graciousnm
Use at your own risk
"""
print(banner)
print(banner2)
host = input("Enter the IP Address to Scan : "+ Fore.BLUE )
print("\n" + Fore.BLUE +"[+] "+ Fore.YELLOW + "Scanning Ports for host : " + Fore.WHITE + host + "\n")
time.sleep(3)
def scan_port(host, port):
try:
#creating a tcp socket connection
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the server on local host and the given port number.
#storing results in a variable
s.settimeout(1)
result = s.connect_ex((host, port))
#getting the open ports printed to the terminal
if result == 0:
print(Fore.GREEN + "[+] " + Fore.WHITE + "Port {} is open".format(port) + Style.RESET_ALL)
#closing connection after scanning for the open ports
s.close()
except socket.error as e:
print("Caught an error while scanning port" + str(e))
#creating threads for each single port to be scanned
def thread_port(ports, host):
threads = []
for port in ports:
t = threading.Thread(target=scan_port, args=(host, port))
threads.append(t)
t.start()
for t in threads:
t.join()
ports = range(1, 63535)
#calling the thread function
thread_port(ports, host)