bin noch ziemlich frisch was Python angeht. Ich habe zwei Nmap Scans in jeweils eine XML gepackt und moechte diese Vergleichen. Es geht darum welche Mac Adressen NICHT in beiden Scans vorkommen.
Ich habe jetzt aber schon beim auslesen der ersten das Problem das er mir den Fehler ausgibt:
Code: Alles auswählen
02:10:18:09:E0:DC
7C:8B:CA:17:6D:28
Traceback (most recent call last):
File "/home/naseweis/Documents/Nmap/compare.py", line 17, in <module>
mac=adress[1].attributes["addr"]
IndexError: list index out of range
Ich weiss warum der Fehler auftritt aber leider nicht wie ich das im Code loesen soll. Ware toll wenn ihr mir helft. Denke das Problem liegt darin, das ich hier
Code: Alles auswählen
mac=adress[1].attributes["addr"]
Code: Alles auswählen
# Compare 2 Scans
from xml.dom import minidom
xmldoc1=minidom.parse("file.xml")
hosts=xmldoc1.getElementsByTagName('host')
for host in hosts:
adress=host.getElementsByTagName("address")
if adress:
mac=adress[1].attributes["addr"]
MAC=mac.value
print("%s"%(MAC))
file.xml
Code: Alles auswählen
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE nmaprun>
<?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?>
<!-- Nmap 7.91 scan initiated Fri Sep 24 17:22:47 2021 as: nmap -sn -oX ./Documents/Nmap/file.xml 192.168.0.0/24 -->
<nmaprun scanner="nmap" args="nmap -sn -oX ./Documents/Nmap/file.xml 192.168.0.0/24" start="1632500567" startstr="Fri Sep 24 17:22:47 2021" version="7.91" xmloutputversion="1.05">
<verbose level="0"/>
<debugging level="0"/>
<host><status state="up" reason="arp-response" reason_ttl="0"/>
<address addr="192.168.0.1" addrtype="ipv4"/>
<address addr="02:10:18:09:E0:DC" addrtype="mac"/>
<hostnames>
<hostname name="kabelbox" type="PTR"/>
</hostnames>
<times srtt="10411" rttvar="8438" to="100000"/>
</host>
<host><status state="up" reason="arp-response" reason_ttl="0"/>
<address addr="192.168.0.28" addrtype="ipv4"/>
<address addr="7C:8B:CA:17:6D:28" addrtype="mac" vendor="Tp-link Technologies"/>
<hostnames>
<hostname name="DESKTOP-2A5NKMC" type="PTR"/>
</hostnames>
<times srtt="256230" rttvar="256230" to="1281150"/>
</host>
<host><status state="up" reason="arp-response" reason_ttl="0"/>
<address addr="192.168.0.90" addrtype="ipv4"/>
<address addr="7C:0B:C6:40:B2:B0" addrtype="mac" vendor="Samsung Electronics"/>
<hostnames>
<hostname name="android-e857b307fef24a39" type="PTR"/>
</hostnames>
<times srtt="184769" rttvar="161219" to="829645"/>
</host>
<runstats><finished time="1632500571" timestr="Fri Sep 24 17:22:51 2021" summary="Nmap done at Fri Sep 24 17:22:51 2021; 256 IP addresses (4 hosts up) scanned in 4.39 seconds" elapsed="4.39" exit="success"/><hosts up="4" down="252" total="256"/>
</runstats>
</nmaprun>