File: cpe.py

package info (click to toggle)
python-libnmap 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,416 kB
  • sloc: xml: 5,572; python: 4,299; makefile: 149
file content (104 lines) | stat: -rw-r--r-- 2,312 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-


class CPE(object):
    """
    CPE class offers an API for basic CPE objects.
    These objects could be found in NmapService or in <os> tag
    within NmapHost.

    :todo: interpret CPE string and provide appropriate API
    """

    def __init__(self, cpestring):
        self._cpestring = cpestring
        zk = [
            "cpe",
            "part",
            "vendor",
            "product",
            "version",
            "update",
            "edition",
            "language",
        ]
        self._cpedict = dict((k, "") for k in zk)
        splitup = cpestring.split(":")
        self._cpedict.update(dict(zip(zk, splitup)))

    @property
    def cpestring(self):
        """
        Accessor for the full CPE string.
        """
        return self._cpestring

    @property
    def cpedict(self):
        """
        Accessor for _cpedict
        """
        return self._cpedict

    def __repr__(self):
        return self._cpestring

    def get_part(self):
        """
        Returns the cpe part (/o, /h, /a)
        """
        return self._cpedict["part"]

    def get_vendor(self):
        """
        Returns the vendor name
        """
        return self._cpedict["vendor"]

    def get_product(self):
        """
        Returns the product name
        """
        return self._cpedict["product"]

    def get_version(self):
        """
        Returns the version of the cpe
        """
        return self._cpedict["version"]

    def get_update(self):
        """
        Returns the update version
        """
        return self._cpedict["update"]

    def get_edition(self):
        """
        Returns the cpe edition
        """
        return self._cpedict["edition"]

    def get_language(self):
        """
        Returns the cpe language
        """
        return self._cpedict["language"]

    def is_application(self):
        """
        Returns True if cpe describes an application
        """
        return self.get_part() == "/a"

    def is_hardware(self):
        """
        Returns True if cpe describes a hardware
        """
        return self.get_part() == "/h"

    def is_operating_system(self):
        """
        Returns True if cpe describes an operating system
        """
        return self.get_part() == "/o"