Warnung: file_put_contents(/home/www/web1/html/php_dev/test.txt) [function.file-put-contents]: failed to open stream: Permission denied in /home/www/web1/html/php_dev/sys/lib.activity.php (Zeile 58)
XML-Datei auswerten mit simpleXML [Archiv] - PHP-Scripte PHP-Tutorials PHP-Jobs und vieles mehr

- Ad -
php-resource




Archiv verlassen und diese Seite im Standarddesign anzeigen :
XML-Datei auswerten mit simpleXML


 
appleactive
08-04-2010, 14:35 
 
Hallo zusammen,

ich möchte gern eine nmap XML Ergebnisdatei auswerten und darstellen.
Bisher ist mir das schon mit der IP, MAC und Vedor ID gelungen. Problematisch stellt sich für mich der Hostname dar (z.B.
wlan.domain.local), da es hier einen weiteren Node (<hostnames> und <hostname ... >) gibt und ich nicht so
recht weiß, wie ich diese richtig ansprechen kann. Da ich kein PHP Profi bin, habe ich die Hoffnung, dass Ihr mir hier aushelfen könnt.

mein bisheriger PHP Code:

<?php

$xml = simplexml_load_file('baseline.xml');
foreach ($xml->host as $host) {

echo '<li>';

foreach($host->address as $address){
echo $address['addrtype'] .': &nbsp;' . $address['addr'] .'&nbsp;&nbsp;' . $address['vendor'] .'&nbsp;&nbsp;' ;
}

echo '</li>';

}


?>

XML Daten baseline.xml:

<?xml version="1.0" ?>
<verbose level="0" />
<debugging level="0" />
<nmaprun>
<host>
<status state="down" reason="no-response"/>
<address addr="192.168.130.0" addrtype="ipv4" />
</host>
<host><status state="up" reason="arp-response"/>
<address addr="192.168.130.1" addrtype="ipv4" />
<address addr="00:12:1B:88:93:0D" addrtype="mac" vendor="Hewlett Packard" />
<hostnames><hostname name="pc1.domain.local" type="PTR" /></hostnames>
</host>
<host><status state="up" reason="arp-response"/>
<address addr="192.168.130.2" addrtype="ipv4" />
<address addr="00:18:39:1A:7B:45" addrtype="mac" vendor="Cisco-Linksys" />
<hostnames><hostname name="wlan.domain.local" type="PTR" /></hostnames>
</host>
</nmaprun>
bisheriges Ergebnis:

ipv4: 192.168.130.0
ipv4: 192.168.130.1 mac: 00:12:1B:88:93:0D Hewlett Packard
ipv4: 192.168.130.2 mac: 00:18:39:1A:7B:45 Cisco-Linksys
Gruß appleactive

 
AmicaNoctis
08-04-2010, 18:06 
 
Hallo,

das geht genauso wie mit host und adress auch:

foreach ($host->hostnames as $names) {
foreach ($names->hostname as $name) {
// ...
}
}


Gruß,

Amica

 
appleactive
08-04-2010, 21:00 
 
@Amica,

Vielen Dank für Deinen Tipp, dass hat funktioniert. :danke:

Falls es für jemanden von Interesse ist, hier das komplett Script:


<?php

$xml = simplexml_load_file('baseline.xml');
foreach ($xml->host as $host) {
foreach($host->status as $status){
if ($status['state'] =='up') {
echo '<li>';
foreach ($host->hostnames->hostname as $hostname) {
echo $hostname['name'];
}
foreach($host->address as $address){
echo $address['addrtype'] .': &nbsp;' . $address['addr']
.'&nbsp;&nbsp;' . $address['vendor'] .'&nbsp;' ;
}
echo '</li>';
}
}
}


?>

Gruß appleactive

- -

Alle Zeitangaben in WEZ +2. Es ist jetzt 16:38 Uhr.