-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportscan.py
More file actions
28 lines (21 loc) · 770 Bytes
/
portscan.py
File metadata and controls
28 lines (21 loc) · 770 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
26
27
import nmap
def rhost():
# ask user the target
target = raw_input("\nTarget IP: ")
target_ports = raw_input("Target PORTS(x-y): ")
# initialize the port scanner
nmScan = nmap.PortScanner()
# scan localhost for ports in range 21-443
nmScan.scan(target, target_ports)
# run a loop to print all the found result about the ports
for host in nmScan.all_hosts():
print("\n--------------------")
print('Host : %s (%s)' % (host, nmScan[host].hostname()))
print('State : %s' % nmScan[host].state())
for proto in nmScan[host].all_protocols():
print('\n----------')
print('Protocol : %s' % proto)
lport = nmScan[host][proto].keys()
lport.sort()
for port in lport:
print ('port : %s\tstate : %s' % (port, nmScan[host][proto][port]['state']))