Python Network Port Scanner (Learning Project)
Python Network Port Scanner (Learning Project)
I made a simple Python port scanner to learn how network connections work.
This project was created for educational purposes to practice:
- Python sockets
- Network programming
- Threading
- Connection handling
- User input processing
Features:
- Scan a target host
- Check available ports
- Multi-threaded scanning
- Simple command-line interface
- Fast results
Example Output:
Code:
Target: 192.168.1.1
Starting scan...
Port 22 OPEN
Port 80 OPEN
Port 443 OPEN
Scan finished.
Code:
Code:
import socket
from concurrent.futures import ThreadPoolExecutor
target = input('Enter target IP: ')
start_port = int(input('Start port: '))
end_port = int(input('End port: '))
def scan_port(port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.5)
result = sock.connect_ex((target, port))
if result == 0:
print('Port ' + str(port) + ' OPEN')
sock.close()
except Exception:
pass
print('Starting scan...')
with ThreadPoolExecutor(max_workers=50) as executor:
for port in range(start_port, end_port + 1):
executor.submit(scan_port, port)
print('Scan finished.')
Possible improvements:
- Service detection
- Saving scan results to a file
- GUI interface
- Better output formatting
Created as a Python learning project to understand how network connections and ports work.
Feedback and suggestions are welcome.