提取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);
?>

 最主要是正則匹配。

導入出來的xml大概內容是這樣的:

<host starttime="1502098117" endtime="1502099466"><status state="up" reason="reset" reason_ttl="236"/>
<address addr="211.143.192.10" addrtype="ipv4"/>
<hostnames>
</hostnames>
<ports><port protocol="tcp" portid="23"><state state="open" reason="syn-ack" reason_ttl="236"/><service name="telnet" method="table" conf="3"/></port>
</ports>
<times srtt="79500" rttvar="62750" to="330500"/>
</host>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM