简体   繁体   中英

How to get information from nmap XML String(IP,Ports) with parser in java

i'm new in coding , i tried to get informations from XML String generated by NMAP4j

<?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>

i tried this code :

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

but i can't get a solution to have objects and manipulating these obects to get all informations

plz help me to get all working with a simple exemple of code so all can understand

Are you trying to parse an existing file ? If so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM