-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportscanner.py
More file actions
32 lines (28 loc) · 1017 Bytes
/
Copy pathportscanner.py
File metadata and controls
32 lines (28 loc) · 1017 Bytes
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
import socket
import time
def scan_target(target, start_port=1, end_port=1024):
print(f"Scanning {target} from port {start_port} to {end_port}")
start_time = time.time()
for port in range(start_port, end_port + 1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
try:
result = s.connect_ex((target, port))
if result == 0:
print(f"[+] Port {port} is OPEN")
s.close()
except KeyboardInterrupt:
print("\n[!] Scan stopped by user.")
break
except socket.gaierror:
print("[!] Hostname could not be resolved.")
break
except socket.error:
print("[!] Couldn't connect to server.")
break
end_time = time.time()
print(f"\nScan completed in {round(end_time - start_time, 2)} seconds.")
# --- Run Scanner ---
if __name__ == "__main__":
target = input("Enter target IP or domain: ")
scan_target(target)