Repository navigation
Expand file tree
/
Copy pathopen_ports.py
More file actions
62 lines (53 loc) · 1.76 KB
/
Copy pathopen_ports.py
File metadata and controls
62 lines (53 loc) · 1.76 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import nmap
from rich.console import Console
from rich.table import Table
from colorama import Fore, init
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
init(autoreset=True)
console = Console()
def banner():
console.print(Fore.GREEN + """
=============================================
Argus - Open Ports Scanning
=============================================
""")
def scan_ports(ip):
nm = nmap.PortScanner()
try:
nm.scan(ip, '1-1024')
open_ports = []
for host in nm.all_hosts():
for proto in nm[host].all_protocols():
open_ports.extend(nm[host][proto].keys())
return open_ports
except Exception as e:
console.print(Fore.RED + f"[!] Error scanning ports: {e}")
return None
def display_ports(open_ports):
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Open Ports", style="cyan", justify="left")
for port in open_ports:
table.add_row(str(port))
console.print(table)
def main(target):
banner()
console.print(Fore.WHITE + f"[*] Scanning open ports for: {target}")
open_ports = scan_ports(target)
if open_ports:
display_ports(open_ports)
else:
console.print(Fore.RED + "[!] No open ports found.")
console.print(Fore.WHITE + "[*] Open ports scanning completed.")
if __name__ == "__main__":
if len(sys.argv) > 1:
target = sys.argv[1]
try:
main(target)
except KeyboardInterrupt:
console.print(Fore.RED + "\n[!] Process interrupted by user.")
sys.exit(1)
else:
console.print(Fore.RED + "[!] No target provided. Please pass an IP address.")
sys.exit(1)