-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.py
33 lines (33 loc) · 1.28 KB
/
scanner.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
import socket
import nmap
import requests
def scan_ports(target, ports):
open_ports = []
print(f"Scanning {target}...")
for port in ports:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1)
result = s.connect_ex((target, port))
if result == 0: # Port is open
open_ports.append(port)
return open_ports
def advanced_scan(target):
nm = nmap.PortScanner()
nm.scan(hosts=target, arguments='-sV')
for host in nm.all_hosts():
print(f"Host: {host} ({nm[host].hostname()})")
for proto in nm[host].all_protocols():
ports = nm[host][proto].keys()
for port in ports:
print(f"Port: {port}, Service: {nm[host][proto][port]['name']}")
def check_vulnerabilities(open_ports):
known_vulns = {80: "HTTP Server potentially outdated", 22: "Default SSH credentials"}
for port in open_ports:
if port in known_vulns:
print(f"Vulnerability found on port {port}: {known_vulns[port]}")
if __name__ == "__main__":
target = input("Enter target IP or hostname: ")
ports = list(range(1, 1025)) # Scan common ports
open_ports = scan_ports(target, ports)
print(f"Open Ports: {open_ports}")
check_vulnerabilities(open_ports)