Changeset 3875

Show
Ignore:
Timestamp:
12/25/08 21:16:05 (4 years ago)
Author:
gpolo
Message:

Removed trailling whitespaces

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branch/NetworkInventory/umitCore/NmapParser.py

    r3874 r3875  
    5151    def __init__(self, id): 
    5252        self.id = id 
    53      
     53 
    5454    # Host ID 
    5555    def get_id(self): 
     
    6464            raise Exception("Invalid id! It must represent an integer, " 
    6565                    "received %r" % id) 
    66      
     66 
    6767    # TCP SEQUENCE 
    6868    def set_tcpsequence(self, sequence): 
     
    7171        else: 
    7272            self._tcpsequence = sequence 
    73      
     73 
    7474    def get_tcpsequence(self): 
    7575        if self._tcpsequence: 
     
    8383        else: 
    8484            self._tcptssequence = sequence 
    85      
     85 
    8686    def get_tcptssequence(self): 
    8787        if self._tcptssequence: 
     
    100100        else: 
    101101            self._ipidsequence = sequence 
    102      
     102 
    103103    def get_ipidsequence(self): 
    104104        if self._ipidsequence: 
     
    109109    def set_osclasses(self, classes): 
    110110        self._osclasses = classes 
    111      
     111 
    112112    def get_osclasses(self): 
    113113        return self._osclasses 
    114     
     114 
    115115    # OS MATCHES 
    116116    def set_osmatches(self, matches): 
    117117        if isinstance(matches, list): 
    118118            self._osmatches = matches 
    119      
     119 
    120120    def get_osmatches(self): 
    121121        if self._osmatches: 
    122122            return self._osmatches 
    123123        return [] 
    124      
     124 
    125125    # OS MATCH 
    126126    def set_osmatch(self, match): 
     
    129129        else: 
    130130            self._osmatch = match 
    131      
     131 
    132132    def get_osmatch(self): 
    133133        if self._osmatch: 
    134134            return self._osmatch 
    135135        return {} 
    136      
     136 
    137137    # OS FINGERPRINT 
    138138    def set_osfingerprint(self, fingerprint): 
     
    141141        else: 
    142142            self._osfingerprint = fingerprint 
    143      
     143 
    144144    def get_osfingerprint(self): 
    145145        if self._osfingerprint: 
     
    150150    def set_ports_used(self, ports): 
    151151        self._ports_used = ports 
    152      
     152 
    153153    def get_ports_used(self): 
    154154        return self._ports_used 
    155      
     155 
    156156    # TRACEROUTE 
    157157    def set_trace(self, trace): 
     
    178178                count = int(hop['ttl']) 
    179179        return count 
    180      
     180 
    181181    # UPTIME 
    182182    # FORMAT: {"seconds":"", "lastboot":""} 
    183183    def set_uptime(self, uptime): 
    184184        self._uptime = uptime 
    185      
     185 
    186186    def get_uptime(self): 
    187187        if self._uptime: 
    188188            return self._uptime 
    189          
     189 
    190190        # Avoid empty dict return 
    191191        return {"seconds":"", "lastboot":""} 
     
    194194    def set_ports(self, port_list): 
    195195        self._ports = port_list 
    196      
     196 
    197197    def get_ports(self): 
    198198        return self._ports 
     
    207207    def set_hostnames(self, hostname_list): 
    208208        self._hostnames = hostname_list 
    209      
     209 
    210210    def get_hostnames(self): 
    211211        return self._hostnames 
     
    216216umitCore.NmapParser.set_ip instead.")) 
    217217        self.set_ip(addr) 
    218      
     218 
    219219    def get_ip_address(self): 
    220220        log.warning(_("umitCore.NmapParser.get_ip_address deprecated! Use \ 
     
    231231    def get_comment(self): 
    232232        return self._comment 
    233      
     233 
    234234    def set_comment(self, comment): 
    235235        self._comment = comment 
     
    240240umitCore.NmapParser.set_mac instead.")) 
    241241        self.set_mac(addr) 
    242      
     242 
    243243    def get_mac_address(self): 
    244244        log.warning(_("umitCore.NmapParser.get_mac_address deprecated! Use \ 
     
    257257umitCore.NmapParser.set_ipv6 instead.")) 
    258258        self.set_ipv6(addr) 
    259      
     259 
    260260    def get_ipv6_address(self): 
    261261        log.warning(_("umitCore.NmapParser.get_ipv6_address deprecated! Use \ 
     
    272272    def set_state(self, status): 
    273273        self._state = status 
    274      
     274 
    275275    def get_state(self): 
    276276        return self._state 
     
    294294        else: 
    295295            hostname = _('Unknown Host') 
    296          
     296 
    297297        return hostname 
    298298 
     
    300300        ports = self.get_ports() 
    301301        open = 0 
    302          
     302 
    303303        for i in ports: 
    304304            port = i['port'] 
     
    306306                if re.findall('open', p['port_state']): 
    307307                    open+=1 
    308          
     308 
    309309        return open 
    310      
     310 
    311311    def get_filtered_ports(self): 
    312312        ports = self.get_ports() 
    313313        extraports = self.get_extraports() 
    314314        filtered = 0 
    315          
     315 
    316316        for i in ports: 
    317317            port = i['port'] 
     
    323323                filtered += int(extra["count"]) 
    324324        return filtered 
    325      
     325 
    326326    def get_closed_ports(self): 
    327327        ports = self.get_ports() 
    328328        extraports = self.get_extraports() 
    329329        closed = 0 
    330          
     330 
    331331        for i in ports: 
    332332            port = i['port'] 
     
    338338                closed += int(extra["count"]) 
    339339        return closed 
    340      
     340 
    341341    def get_scanned_ports(self): 
    342342        ports = self.get_ports() 
    343343        extraports = self.get_extraports() 
    344344        scanned = 0 
    345          
     345 
    346346        for i in ports: 
    347347            port = i['port'] 
     
    443443    def set_profile(self, profile): 
    444444        self.nmap['nmaprun']['profile'] = profile 
    445      
     445 
    446446    def get_profile_name(self): 
    447447        return self.nmap['nmaprun'].get('profile_name', '') 
     
    449449    def set_profile_name(self, name): 
    450450        self.nmap['nmaprun']['profile_name'] = name 
    451      
     451 
    452452    def get_profile_description(self): 
    453453        return self.nmap['nmaprun'].get('description', '') 
     
    455455    def set_profile_description(self, description): 
    456456        self.nmap['nmaprun']['description'] = description 
    457      
     457 
    458458    def get_profile_hint(self): 
    459459        return self.nmap['nmaprun'].get('hint', '') 
     
    461461    def set_profile_hint(self, hint): 
    462462        self.nmap['nmaprun']['hint'] = hint 
    463      
     463 
    464464    def get_profile_annotation(self): 
    465465        return self.nmap['nmaprun'].get('annotation', '') 
     
    467467    def set_profile_annotation(self, annotation): 
    468468        self.nmap['nmaprun']['annotation'] = annotation 
    469      
     469 
    470470    def get_profile_options(self): 
    471471        options = self.nmap['nmaprun'].get('options', '') 
     
    483483            raise Exception("Profile option error: wrong argument format! " 
    484484                    "Need a string, list or dict.") 
    485      
     485 
    486486    def get_target(self): 
    487487        return self.nmap['nmaprun'].get('target', '') 
     
    495495    def set_nmap_output(self, nmap_output): 
    496496        self.nmap['nmaprun']['nmap_output'] = nmap_output 
    497      
     497 
    498498    def get_debugging_level (self): 
    499499        return self.nmap.get('debugging', '') 
     
    501501    def set_debugging_level(self, level): 
    502502        self.nmap['debugging'] = level 
    503      
     503 
    504504    def get_verbose_level (self): 
    505505        return self.nmap.get('verbose', '') 
     
    507507    def set_verbose_level(self, level): 
    508508        self.nmap['verbose'] = level 
    509      
     509 
    510510    def get_scaninfo(self): 
    511511        return self.nmap.get('scaninfo', '') 
     
    513513    def set_scaninfo(self, info): 
    514514        self.nmap['scaninfo'] = info 
    515      
     515 
    516516    def get_services_scanned (self): 
    517517        if self._services_scanned is None: 
    518518            return self._services_scanned 
    519          
     519 
    520520        services = [] 
    521521        for scan in self.nmap.get('scaninfo', []): 
     
    549549        if self._num_services is None: 
    550550            return self._num_services 
    551          
     551 
    552552        num = 0 
    553553        for n in self.nmap.get('scaninfo', []): 
     
    576576            raise Exception("Wrong date format. Date should be saved \ 
    577577in epoch format!") 
    578      
     578 
    579579    def get_open_ports(self): 
    580580        ports = 0 
     
    598598    def get_closed_ports(self): 
    599599        ports = 0 
    600          
     600 
    601601        for h in self.nmap['hosts']: 
    602602            ports += h.get_closed_ports() 
     
    606606    def get_formated_date(self): 
    607607        date = self.get_date() 
    608         return "%s %s, %s - %s:%s" % (months[date[1]],  
    609                                       str(date[2]),  
     608        return "%s %s, %s - %s:%s" % (months[date[1]], 
     609                                      str(date[2]), 
    610610                                      str(date[0]), 
    611                                       str(date[3]).zfill(2),  
     611                                      str(date[3]).zfill(2), 
    612612                                      str(date[4]).zfill(2)) 
    613613 
     
    617617    def set_scanner(self, scanner): 
    618618        self.nmap['nmaprun']['scanner'] = scanner 
    619      
     619 
    620620    def get_scanner_version (self): 
    621621        return self.nmap['nmaprun'].get('version', '') 
     
    637637            except: 
    638638                pass 
    639          
     639 
    640640        return addresses 
    641641 
     
    653653            except: 
    654654                pass 
    655          
     655 
    656656        return addresses 
    657657 
     
    682682        for port in self.nmap.get('hosts', []): 
    683683            ports.append(port.get_ports()) 
    684          
     684 
    685685        return ports 
    686686 
     
    694694    def get_trace(self): 
    695695        return self.nmap.get('trace', None) 
    696      
    697      
     696 
     697 
    698698    def get_runstats(self): 
    699699        return self.nmap.get('runstats', None) 
     
    701701    def set_runstats(self, stats): 
    702702        self.nmap['runstats'] = stats 
    703      
     703 
    704704    def get_hosts_down(self): 
    705705        return int(self.nmap['runstats'].get('hosts_down', '0')) 
     
    707707    def set_hosts_down(self, down): 
    708708        self.nmap['runstats']['hosts_down'] = int(down) 
    709      
     709 
    710710    def get_hosts_up(self): 
    711711        return int(self.nmap['runstats'].get('hosts_up', '0')) 
     
    713713    def set_hosts_up(self, up): 
    714714        self.nmap['runstats']['hosts_up'] = int(up) 
    715      
     715 
    716716    def get_hosts_scanned(self): 
    717717        return int(self.nmap['runstats'].get('hosts_scanned', '0')) 
     
    719719    def set_hosts_scanned(self, scanned): 
    720720        self.nmap['runstats']['hosts_scanned'] = int(scanned) 
    721      
     721 
    722722    def get_finish_time (self): 
    723723        return time.localtime(int(self.nmap['runstats'].get('finished_time', 
     
    738738    def set_scan_name(self, scan_name): 
    739739        self.nmap["scan_name"] = scan_name 
    740      
     740 
    741741    def get_formated_finish_date(self): 
    742742        date = self.get_finish_time() 
    743         return "%s %s, %s - %s:%s" % (months[date[1]],  
    744                                       str(date[2]),  
     743        return "%s %s, %s - %s:%s" % (months[date[1]], 
     744                                      str(date[2]), 
    745745                                      str(date[0]), 
    746                                       str(date[3]).zfill(2),  
     746                                      str(date[3]).zfill(2), 
    747747                                      str(date[4]).zfill(2)) 
    748748 
     
    750750        found = re.findall ('(-o[XGASN]{1}) {0,1}', command) 
    751751        splited = command.split (' ') 
    752          
     752 
    753753        if found: 
    754754            for option in found: 
     
    756756                del(splited[pos+1]) 
    757757                del(splited[pos]) 
    758          
     758 
    759759        return ' '.join (splited) 
    760760 
     
    764764    profile = property(get_profile, set_profile) 
    765765    profile_name = property(get_profile_name, set_profile_name) 
    766     profile_description = property(get_profile_description,  
     766    profile_description = property(get_profile_description, 
    767767                                   set_profile_description) 
    768768    profile_hint = property(get_profile_hint, set_profile_hint) 
    769     profile_annotation = property(get_profile_annotation,  
     769    profile_annotation = property(get_profile_annotation, 
    770770                                  set_profile_annotation) 
    771771    profile_options = property(get_profile_options, set_profile_options) 
     
    805805    trace = property(get_trace) 
    806806    hops = property(get_hops) 
    807      
     807 
    808808    _num_services = None 
    809809    _services_scanned = None 
     
    821821        self.in_os = False 
    822822        self.list_extraports = [] 
    823          
     823 
    824824        # Creating a traceroute condition 
    825825        self.in_trace = False 
    826          
     826 
    827827        self.nmap_xml_file = None 
    828828        self.unsaved = False 
     
    850850    def _parse_nmaprun(self, attrs): 
    851851        run_tag = "nmaprun" 
    852          
     852 
    853853        self.nmap[run_tag]["nmap_output"] = attrs.get("nmap_output", "") 
    854854        self.nmap[run_tag]["profile"] = attrs.get("profile", "") 
     
    863863        self.nmap[run_tag]["scanner"] = attrs.get("scanner", "") 
    864864        self.nmap[run_tag]["version"] = attrs.get("version", "") 
    865         self.nmap[run_tag]["xmloutputversion"] = attrs.get("xmloutputversion",  
     865        self.nmap[run_tag]["xmloutputversion"] = attrs.get("xmloutputversion", 
    866866                                                           "") 
    867867        self.nmap["scan_name"] = attrs.get("scan_name", "") 
     
    869869    def _parse_scaninfo(self, attrs): 
    870870        dic = {} 
    871          
     871 
    872872        dic["type"] = attrs.get("type", "") 
    873873        dic["protocol"] = attrs.get("protocol", "") 
    874874        dic["numservices"] = attrs.get("numservices", "") 
    875875        dic["services"] = attrs.get("services", "") 
    876          
     876 
    877877        self.nmap["scaninfo"].append(dic) 
    878878 
     
    923923 
    924924    def _parse_host_port(self, attrs): 
    925         self.dic_port = {"protocol":attrs.get("protocol", ""),  
     925        self.dic_port = {"protocol":attrs.get("protocol", ""), 
    926926                         "portid":attrs.get("portid", "")} 
    927927 
     
    946946               tmp['accuracy'] > last_osmatch['accuracy']: 
    947947                self.host_info.set_osmatch(tmp) 
    948              
     948 
    949949        self.list_osmatches.append(tmp) 
    950950 
    951951    def _parse_host_portused(self, attrs): 
    952         self.list_portused.append(self._parsing(attrs,  
     952        self.list_portused.append(self._parsing(attrs, 
    953953                                                ['state','proto','portid'])) 
    954954 
     
    959959                                                       'osgen', 
    960960                                                       'accuracy'])) 
    961      
     961 
    962962    def _parse_host_osfingerprint(self, attrs): 
    963963        self.host_info.set_osfingerprint(self._parsing(attrs, ['fingerprint'])) 
     
    981981                                                             'difficulty', 
    982982                                                             'values'])) 
    983      
     983 
    984984    def _parse_host_tcptssequence(self, attrs): 
    985985        self.host_info.set_tcptssequence(self._parsing(attrs, ['class', 
     
    996996        self.list_hop.append(tmp) 
    997997 
    998          
     998 
    999999    def startElement(self, name, attrs): 
    10001000        if name == "nmaprun": 
     
    10611061        elif self.in_host and name == "ipidsequence": 
    10621062            self._parse_host_ipidsequence(attrs) 
    1063         # Creating a traceroute condition  
     1063        # Creating a traceroute condition 
    10641064        elif self.in_host and name == "trace": 
    10651065            self.in_trace = True 
     
    10991099            del(self.list_osclass) 
    11001100            del(self.list_osmatches) 
    1101              
     1101 
    11021102        # Creating a traceroute condition 
    11031103        elif self.in_host and name == "trace": 
     
    12111211                            Attributes(dict(name = hname.get("hostname", ""), 
    12121212                                        type = hname.get("hostname_type", "")))) 
    1213                      
     1213 
    12141214                    self.write_parser.endElement("hostname") 
    12151215 
     
    12671267            # OS element 
    12681268            self.write_parser.startElement("os", Attributes({})) 
    1269              
     1269 
    12701270            ## Ports used elements 
    12711271            for pu in host.ports_used: 
     
    12981298                                    accuracy = om.get("accuracy", "")))) 
    12991299                    self.write_parser.endElement("osmatch") 
    1300              
     1300 
    13011301            ## Osfingerprint element 
    13021302            if isinstance(host.osfingerprint, dict): 
    13031303                self.__remove_none_keys(host.osfingerprint) 
    1304                 self.write_parser.startElement("osfingerprint",  
     1304                self.write_parser.startElement("osfingerprint", 
    13051305                    Attributes(dict(fingerprint = \ 
    13061306                                    host.osfingerprint.get("fingerprint", "")))) 
     
    14041404            else: 
    14051405                return xml_file 
    1406      
     1406 
    14071407    def __remove_none_keys(self, dic): 
    14081408        pop_list = [] 
     
    14121412        for k in pop_list: 
    14131413            dic.pop(k) 
    1414              
     1414 
    14151415    def set_unsaved(self): 
    14161416        self.unsaved = True 
     
    14221422    parser = make_parser() 
    14231423    nmap_parser = NmapParserSAX() 
    1424      
     1424 
    14251425    parser.setContentHandler(nmap_parser) 
    14261426    nmap_parser.set_parser(parser)