【问题标题】:How to get information from nmap XML String(IP,Ports) with parser in java如何在java中使用解析器从nmap XML字符串(IP,端口)获取信息
【发布时间】:2012-12-28 11:54:54
【问题描述】:

我是编码新手,我试图从 NMAP4j

生成的 XML 字符串中获取信息
<?xml version="1.0"?>
<?xml-stylesheet href="file:///usr/local/share/nmap/nmap.xsl" type="text/xsl"?>
<!-- Nmap 6.01 scan initiated Mon Jan 14 13:56:47 2013 as: /usr/local/bin/nmap -&#45;datadir /usr/local/share/nmap -T4 -oX - 192.168.1.1 -->
<nmaprun scanner="nmap" args="/usr/local/bin/nmap -&#45;datadir /usr/local/share/nmap -T4 -oX - 192.168.1.1" start="1358168207" startstr="Mon Jan 14 13:56:47 2013" version="6.01" xmloutputversion="1.04">
<scaninfo type="syn" protocol="tcp" numservices="1000" services="1,3-4,..."/>
<verbose level="0"/>
<debugging level="0"/>
<host starttime="1358168207" endtime="1358168209"><status state="up" reason="arp-response"/>
<address addr="192.168.1.1" addrtype="ipv4"/>
<address addr="xxx" addrtype="mac" vendor="yyy"/>
<hostnames>
</hostnames>
<ports><extraports state="closed" count="996">
<extrareasons reason="resets" count="996"/>
</extraports>
<port protocol="tcp" portid="21"><state state="open" reason="syn-ack" reason_ttl="64"/><service name="ftp" method="table" conf="3"/></port>
<port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="64"/><service name="ssh" method="table" conf="3"/></port>
</ports>
<times srtt="36813" rttvar="25229" to="137729"/>
</host>
<runstats><finished time="1358168209" timestr="Mon Jan 14 13:56:49 2013" elapsed="2.48" summary="Nmap done at Mon Jan 14 13:56:49 2013; 1 IP address (1 host up) scanned in 2.48 seconds" exit="success"/><hosts up="1" down="0" total="1"/>
</runstats>
</nmaprun>

我试过这段代码:

String nmapRun = nmap4j.getOutput() ;
OnePassParser opp = new OnePassParser() ;
NMapRun nmapRun1 = opp.parse( nmapRun, OnePassParser.STRING_INPUT ) ;

但我无法获得拥有对象并操纵这些对象以获取所有信息的解决方案

请帮助我使用一个简单的代码示例让所有人都能理解

【问题讨论】:

    标签: java parsing xml-parsing sax nmap


    【解决方案1】:

    您是否正在尝试解析现有文件?如果是这样:

    OnePassParser opp = new OnePassParser() ;
    NMapRun nmapRun = opp.parse( fileName, OnePassParser.FILE_NAME_INPUT ) ;
    

    【讨论】:

    • 没有字符串输入,我找不到如何获取对象或信息
    • 嗨,我在阅读文档后找到了解决方案,这是获取第一个 HOST OnePassParser opp = new OnePassParser() 的供应商的示例; NMapRun nmapRun1 = opp.parse( nmapRun, OnePassParser.STRING_INPUT ) ; ArrayList 主机=nmapRun1.getHosts(); System.out.println(hosts.get(0).getAddress().getVendor());
    • 嗨 - 你能得到其他 XML 标记的内容吗?例如使用“--script=ssl-cert ssl”标志的结果
    猜你喜欢
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    相关资源
    最近更新 更多