可我浪费着我寒冷的年华

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

 

posted @ 2017-08-08 14:41  珍惜少年时  阅读(3092)  评论(0编辑  收藏  举报
可我浪费着我寒冷的年华