T
T
TODO•SEC
Search…
PortScanner.py
TCP Port Scanner script from Python section of PTSv4 (eLearnSecurity)
1
# Goal - Port scanner
2
import socket
3
4
TARGET = input("Server's IP: ")
5
PRANGE = input("Enter port range i.e 1-100: ")
6
7
lowport = int(PRANGE.split('-')[0])
8
highport = int(PRANGE.split('-')[1])
9
10
# Output given range and target
11
print('Scanning host ', TARGET, 'from port ', lowport, 'to port ', highport)
12
13
# For loop iterates attempting connections on all ports in range
14
# 0 = port open; otherwise closed.
15
for port in range(lowport, highport):
16
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17
status = s.connect_ex((TARGET, port))
18
if(status == 0):
19
print('*** Port', port, '- OPEN ***')
20
else:
21
print('*** Port', port, '- CLOSED ***')
22
s.close()
Copied!
Last modified 8d ago
Copy link