forked from bodik/python-libnmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_cpe.py
More file actions
39 lines (34 loc) · 1.28 KB
/
check_cpe.py
File metadata and controls
39 lines (34 loc) · 1.28 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
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from libnmap.parser import NmapParser
rep = NmapParser.parse_fromfile("libnmap/test/files/full_sudo6.xml")
print(
"Nmap scan discovered {0}/{1} hosts up".format(
rep.hosts_up, rep.hosts_total
)
)
for _host in rep.hosts:
if _host.is_up():
print(
"+ Host: {0} {1}".format(_host.address, " ".join(_host.hostnames))
)
# get CPE from service if available
for s in _host.services:
print(
" Service: {0}/{1} ({2})".format(
s.port, s.protocol, s.state
)
)
# NmapService.cpelist returns an array of CPE objects
for _serv_cpe in s.cpelist:
print(" CPE: {0}".format(_serv_cpe.cpestring))
if _host.os_fingerprinted:
print(" OS Fingerprints")
for osm in _host.os.osmatches:
print(
" Found Match:{0} ({1}%)".format(osm.name, osm.accuracy)
)
# NmapOSMatch.get_cpe() method return an array of string
# unlike NmapOSClass.cpelist which returns an array of CPE obj
for cpe in osm.get_cpe():
print("\t CPE: {0}".format(cpe))