nmap xml处理

<?php
$file_path = "xiamen_scan_ok.xml";
$file = fopen($file_path, "r");

//输出文本中所有的行,直到文件结束为止。
global $ip;
while(!feof($file))
{
    $line= fgets($file);//fgets()函数从文件指针中读取一行'
    //echo $line;
    preg_match("/address addr="(.+)" addrtype="ipv4"/", $line,$ips);//匹配IP
    preg_match("/<port protocol="tcp" portid="(.+)"><state state="open".+<service name="(S+)" /", $line,$port);//匹配端口

    if ($ips) {
        $ip = $ips;
    }
    if ($port) {
        echo $ip[1].":".$port[1].":".$port[2];
        echo '<br>';
    }
}
fclose($file);
?>
原文地址:https://www.cnblogs.com/nul1/p/13954039.html