File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 88def parse_nmap_xml_file (input_file ):
99 result_dict = {} #To store the port_number:service_name
1010 host_status = "N/A"
11- if os .path .isfile (input_file ): #Check if the file exist
12- with open (input_file ) as fd :
13- col_ordered_dict = xmltodict .parse (fd .read ()) #Convert the xml file to dictonary to process it
14- host_status = col_ordered_dict ['nmaprun' ]['runstats' ]['hosts' ]['@up' ] #Get the Host status Valye 1 or 0
15- if host_status == "1" : #if Host status is up then process further
16- for items in col_ordered_dict ['nmaprun' ]['host' ]['ports' ]['port' ]: #Loop Through all the open ports and get the list
17- if items ['state' ]['@state' ]== "open" :
18- result_dict [items ['@portid' ]] = items ['service' ]['@name' ] #Save Port Number and Service Name into Dict
11+ try :
12+ if os .path .isfile (input_file ): #Check if the file exist
13+ with open (input_file ) as fd :
14+ col_ordered_dict = xmltodict .parse (fd .read ()) #Convert the xml file to dictonary to process it
15+ host_status = col_ordered_dict ['nmaprun' ]['runstats' ]['hosts' ]['@up' ] #Get the Host status Valye 1 or 0
16+ if host_status == "1" : #if Host status is up then process further
17+ for items in col_ordered_dict ['nmaprun' ]['host' ]['ports' ]['port' ]: #Loop Through all the open ports and get the list
18+ if items ['state' ]['@state' ]== "open" :
19+ result_dict [items ['@portid' ]] = items ['service' ]['@name' ] #Save Port Number and Service Name into Dict
20+ except Exception as e :
21+ #print(e)
22+ host_status = "ERROR"
1923 return host_status ,result_dict
2024
2125
You can’t perform that action at this time.
0 commit comments