8 fields = str.split('/')
11 def get_state_from_port(host):
12 #nmap = os.popen("nmap -oG - -P0 -p 22,80,806 %s 2>/dev/null | tr ':' '\n' | grep -E 'tcp|Timeout'" % host, 'r')
13 nmap = os.popen("nmap -oG - -p 22,80,806 %s 2>/dev/null | tr ':' '\n' | grep -E 'tcp|Timeout'" % host, 'r')
14 line = nmap.readline()
21 ##### 0 0 1 - firewall
22 ##### 1 0 1 - error or firewall
23 ##### 0 1 1 - firewall
32 mapping = {'down' : 0,
38 #print "--%s--" % line
39 #print "--%s--" % type(line)
40 if line.strip() == "" or line.strip() == "Timeout":
41 return mapping["down"]
42 (p22, p80, p806) = line.split()
43 if port_status(p22) == "open" and \
44 port_status(p80) == "open" and \
45 port_status(p806) == "open":
46 return mapping["boot"]
47 elif port_status(p22) == "open" and port_status(p806) != "open":
48 return mapping["debug"]
49 elif port_status(p806) == "open":
50 return mapping["firewall"]
52 return mapping["unknown"]
54 print get_state_from_port(sys.argv[1])