zoukankan      html  css  js  c++  java
  • 提取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>
  • 相关阅读:
    Django drf 功能组件
    Django drf 视图家族
    Django drf初级
    Django drf序列化器 Serializer
    VUE 全整理
    Django Xadmin的安装方式
    python virtualenv虚拟环境搭建
    版本控制器:操作流程
    版本控制器:GIT线上操作
    《剑指offer》---跳台阶问题
  • 原文地址:https://www.cnblogs.com/xishaonian/p/7306727.html
Copyright © 2011-2022 走看看