Receiving XML exception from nmap.scan() results. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Receiving XML exception from nmap.scan() results. (/thread-23840.html) |
Receiving XML exception from nmap.scan() results. - PythonNmap - Jan-20-2020 Hi All, I'm making use of the python-nmap library. However, running a basic scan against 10.0.0.17/255.255.255.0 or more precisely 10.0.0.17/24, yields the following exception on the returned XML results: The command is:raw = nm.scan(hosts=vlan+'/'+str(cidr), arguments=' -v -sn -n -oG - ')which translates to: nmap -v -sn -n -oG - 10.0.0.117/24Raw output would be similar to this: # nmap -v -sn -n -oG - 10.0.0.117/24 # Nmap 6.40 scan initiated Sun Jan 19 23:22:18 2020 as: nmap -v -sn -n -oG - 10.0.0.117/24 # Ports scanned: TCP(0;) UDP(0;) SCTP(0;) PROTOCOLS(0;) Host: 10.0.0.0 () Status: Down Host: 10.0.0.1 () Status: Up Host: 10.0.0.2 () Status: Down Host: 10.0.0.3 () Status: Down . . . Host: 10.0.0.252 () Status: Down Host: 10.0.0.253 () Status: Down Host: 10.0.0.254 () Status: Down Host: 10.0.0.255 () Status: Down # Nmap done at Sun Jan 19 23:22:22 2020 -- 256 IP addresses (7 hosts up) scanned in 3.62 secondsWhen running the resulting XML through some parsing, I get this (snippet): The unaltered error: Perhaps the -- in the above is causing the XML to throw an exception? Or the #'s ?Thx, TK RE: Receiving XML exception from nmap.scan() results. - buran - Jan-20-2020 I think it's the # - traceback is clear - line 4, column1.And you can validate your snippet against xml validators and they also raise error on # .Now - should it be there is another question. According to their sample output - no, it shouldn't be there https://nmap.org/book/output-formats-xml-output.html Note that there is another one on line 8 - # Ports scanned: TCP(0;) UDP(0;) SCTP(0;) PROTOCOLS(0;) Maybe ask nmap support why it's in their xml output? RE: Receiving XML exception from nmap.scan() results. - PythonNmap - Jan-20-2020 Yeah, after I posted I used a validator. Confirmed the same message. However, the # is expected. There's a few formats nmap can output in, including XML. Meaning, I don't need to use python-nmap's XML generator, using instead an XML reader on nmap results captured from a system command. The option is -oX instead of -oG to nmap. I'll need to research this. Wouldn't this make it more of a python-nmap coding question then? The #'s invalidate a ton of examples. Thanks Buran! Another clue. Looking closely though, line 3, that's the comment on line 4 encoded in HTML comments. What this tells me is that the python-nmap logic did work converting a comment to HTML format but left the original comment in place as well. Why leave it twice? This suggests the #'s should have been removed once converted to HTML comments. Perhaps I should reach out to the developers of python-nmap to see if there's a way around this? Thx, TK RE: Receiving XML exception from nmap.scan() results. - buran - Jan-20-2020 Maybe you shouldn't supply -oG option in arguments, Nowhere in the examples and the docs they force -oG (i.e. Grepable output format).Looking at the source code, they force -oX option. RE: Receiving XML exception from nmap.scan() results. - PythonNmap - Jan-21-2020 Hm. Tried to use -oX . python-nmap tried to wrap XML into XML.Now I just tried using without -oG and without -oX . Now it works. Cheers, TK |