-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathopen_ports.py
More file actions
34 lines (28 loc) · 1 KB
/
open_ports.py
File metadata and controls
34 lines (28 loc) · 1 KB
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
28
29
30
31
32
33
34
#To use this function ,use following commands in scanner.py
#import open_ports
#open_ports.openPorts()
import scanner
YELLOW = scanner.YELLOW
RED = scanner.RED
END = scanner.END
BLUE = scanner.BLUE
WHITE = scanner.WHITE
def openPorts() :
scanner.getNodes()
import nmap
nm = nmap.PortScanner()
for host in scanner.nodelist :
try:
a = nm.scan(hosts=host[0])
b = nm[host[0]].all_tcp()
c = nm[host[0]].all_udp()
print('{0}open Tcp ports for ip {1}'+host[0]+'{2} are {3}'+str(b)).format(YELLOW,RED,YELLOW,END)
if b:
for port in b :
print('{0}service running at port {1}' + str(port) + ' {2}is {3}' + a['scan'][host[0]]['tcp'][port]['name']+'{4}').format(WHITE,RED,WHITE,BLUE,END)
print('{0}open udp ports for ip {1}'+host[0]+'{2} are {3}'+str(c)).format(YELLOW,RED,YELLOW,END)
if c:
for port in c :
print('{0}service running at port {1}' + str(port) + '{2} is {3}' + a['scan'][host[0]]['udp'][port]['name']+'{5}').format(WHITE,RED,WHITE,BLUE,END)
except:
continue