-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.py
More file actions
54 lines (31 loc) · 1.09 KB
/
Copy pathscanner.py
File metadata and controls
54 lines (31 loc) · 1.09 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
import socket
print("=" * 40)
print(" TCP PORT SCANNER")
print("=" * 40)
target = input("Enter Target IP or Website: ")
start_port = int(input("Enter Start Port: "))
end_port = int(input("Enter End Port: "))
print(f"\nScanning Target: {target}")
print(f"Scanning Ports from {start_port} to {end_port}\n")
try:
file = open("results.txt", "w")
for port in range(start_port, end_port + 1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = s.connect_ex((target, port))
if result == 0:
output = f"[OPEN] Port {port}"
print(output)
file.write(output + "\n")
else:
output = f"[CLOSED] Port {port}"
print(output)
file.write(output + "\n")
s.close()
file.close()
print("\nScan Completed Successfully!")
print("Results saved in results.txt")
except socket.gaierror:
print("Hostname could not be resolved")
except socket.error:
print("Server not responding")