Skip to content

Commit 2281698

Browse files
Add files via upload
Initial commit — Added basic Python port scanner
1 parent e52df59 commit 2281698

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

port_scanner.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import socket
2+
from datetime import datetime
3+
4+
# Target to scan
5+
target = input("Enter target IP or domain: ")
6+
7+
# Banner
8+
print("-" * 50)
9+
print(f"Scanning Target: {target}")
10+
print("Scanning started at: " + str(datetime.now()))
11+
print("-" * 50)
12+
13+
try:
14+
for port in range(1, 1025): # You can change the port range
15+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16+
socket.setdefaulttimeout(1)
17+
result = s.connect_ex((target, port))
18+
if result == 0:
19+
print(f"Port {port} is open")
20+
s.close()
21+
22+
except KeyboardInterrupt:
23+
print("\nExiting Program.")
24+
except socket.gaierror:
25+
print("\nHostname Could Not Be Resolved.")
26+
except socket.error:
27+
print("\nServer not responding.")
28+

0 commit comments

Comments
 (0)