提取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