-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathport_scanner.py
More file actions
25 lines (21 loc) · 792 Bytes
/
port_scanner.py
File metadata and controls
25 lines (21 loc) · 792 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
import subprocess
# Specify the IP address of the device you want to scan
device_ip = '192.168.88.74'
# Run the nmap command to scan all ports
nmap_command = ['nmap', '-p-', device_ip]
process = subprocess.Popen(nmap_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# Check the nmap output to find open ports
open_ports = []
for line in output.decode().split('\n'):
if '/tcp' in line and 'open' in line:
port = line.split('/')[0]
open_ports.append(port)
print("Open port found on {}: {}".format(device_ip, port))
# Print the open ports
if open_ports:
print("\nOpen ports on {}: ".format(device_ip))
for port in open_ports:
print(port)
else:
print("No open ports found on {}.".format(device_ip))