python-masscan
python-masscan copied to clipboard
masscan.masscan.NetworkConnectionError: network is unreachable. part deux
When I add some output options to the scan to store the output into an XML file, the scan happens, and the file is created, but I get the output "masscan.masscan.NetworkConnectionError: network is unreachable."
Details:
Python 3.8.1 (default, Jan 3 2020, 22:44:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import masscan
>>> mas = masscan.PortScanner()
>>> mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile')
[2020-01-12 02:03:06,241] [DEBUG] [masscan.py 10 line] Scan parameters: "masscan -oX - 192.168.1.111 -p 1-1000 --max-rate=1000 -oX testfile"
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 384, in analyse_masscan_xml_scan
dom = ET.fromstring(self._masscan_last_output)
File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1321, in XML
return parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 325, in scan
return self.analyse_masscan_xml_scan(
File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 387, in analyse_masscan_xml_scan
raise NetworkConnectionError("network is unreachable.")
masscan.masscan.NetworkConnectionError: network is unreachable.
>>> quit()
root@a23c6822251f:/opt/apps/src# cat testfile
<?xml version="1.0"?>
<!-- masscan v1.0 scan -->
<nmaprun scanner="masscan" start="1578794586" version="1.0-BETA" xmloutputversion="1.03">
<scaninfo type="syn" protocol="tcp" />
<host endtime="1578794586"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="445"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="139"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="111"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="53"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<runstats>
<finished time="1578794599" timestr="2020-01-12 02:03:19" elapsed="13" />
<hosts up="6" down="0" total="6" />
</runstats>
</nmaprun>
Additionally I see you pass the arguments '-oX -' which should output in XML format, but the format comes out in JSON. I don't understand why.
Ok, I think I get the -oX - thing. You take the XML output and run it through def analyse_masscan_xml_scan which then turns it into a dictionary. Any reason why you do that rather than use -oJ?
hi, @sirmodok
- Here use "
-
" instead of stdin, stdout -
-oX
This is an ancient problem and I think a roadmap is needed to solve it - Regarding "masscan.masscan.NetworkConnectionError: network is unreachable" There is a problem with the processing method here, I think the next version will handle it well
similar to #27
I use multiprocessing in python to invoke masscan and also find "masscan.masscan.NetworkConnectionError: network is unreachable. " exception, I don't know how to fix it.
@csskysea Please confirm that you can access the target network.
@MyKings of course I can access the target network, because it's no problem using single process.
Post a screenshot and operating environment description.
When I add some output options to the scan to store the output into an XML file, the scan happens, and the file is created, but I get the output "masscan.masscan.NetworkConnectionError: network is unreachable."
Details:
Python 3.8.1 (default, Jan 3 2020, 22:44:00) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import masscan >>> mas = masscan.PortScanner() >>> mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile') [2020-01-12 02:03:06,241] [DEBUG] [masscan.py 10 line] Scan parameters: "masscan -oX - 192.168.1.111 -p 1-1000 --max-rate=1000 -oX testfile" Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 384, in analyse_masscan_xml_scan dom = ET.fromstring(self._masscan_last_output) File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1321, in XML return parser.close() xml.etree.ElementTree.ParseError: no element found: line 1, column 0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 325, in scan return self.analyse_masscan_xml_scan( File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 387, in analyse_masscan_xml_scan raise NetworkConnectionError("network is unreachable.") masscan.masscan.NetworkConnectionError: network is unreachable. >>> quit() root@a23c6822251f:/opt/apps/src# cat testfile <?xml version="1.0"?> <!-- masscan v1.0 scan --> <nmaprun scanner="masscan" start="1578794586" version="1.0-BETA" xmloutputversion="1.03"> <scaninfo type="syn" protocol="tcp" /> <host endtime="1578794586"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="445"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host> <host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host> <host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="139"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host> <host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="111"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host> <host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host> <host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="53"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host> <runstats> <finished time="1578794599" timestr="2020-01-12 02:03:19" elapsed="13" /> <hosts up="6" down="0" total="6" /> </runstats> </nmaprun>
Additionally I see you pass the arguments '-oX -' which should output in XML format, but the format comes out in JSON. I don't understand why.
I encountered a similar error. The reason that you can't connect, seems to be you don't have permission to do so. Try giving sudo=True.
mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile',sudo=True)
In my case it worked.
hi, @sirmodok
- Here use "
-
" instead of stdin, stdout-oX
This is an ancient problem and I think a roadmap is needed to solve it- Regarding "masscan.masscan.NetworkConnectionError: network is unreachable" There is a problem with the processing method here, I think the next version will handle it well
similar to #27
The problem I've noticed is
try:
dom = ET.fromstring(self._masscan_last_output)
except Exception:
if "found=0" in masscan_err:
raise NetworkConnectionError("network is unreachable.")
if len(masscan_err_keep_trace) > 0:
raise PortScannerError(masscan_err)
else:
raise PortScannerError(self._masscan_last_output)
will spit out "network is unreachable" if the xml list is empty, even though the network is reachable - the ports I've looked for just aren't open.
Great module though, I'm still playing with it :). Keep up the good work.
Still encountering this issue in version 1.3.2 with -oG, -oJ and -oX
Still masscan.masscan.NetworkConnectionError: network is unreachable.
Still masscan.masscan.NetworkConnectionError: network is unreachable.
I believe the error of "Network is Unreachable" should really read "No ports found" and is just a simple typo.