C++解析nmap xml输出以及类似的Boost xml_parser
C++ Parsing nmap xml output and similar with Boost xml_parser
对于xml:
<?xml version="1.0" ?>
<?xml-stylesheet href="file:///usr/share/nmap/nmap.xsl" type="text/xsl"?>
<!-- Nmap 5.21 scan initiated Tue Feb 3 12:01:07 2015 as: nmap -v -R -sP -PS80 --traceroute -oX /tmp/SCB_nmap_tcp_traceroute.xml 54.209.104.11 -->
<nmaprun scanner="nmap" args="nmap -v -R -sP -PS80 --traceroute -oX /tmp/SCB_nmap_tcp_traceroute.xml 54.209.104.11" start="1422964867" startstr="Tue Feb 3 12:01:07 2015" version="5.21" xmloutputversion="1.03">
<verbose level="1" />
<debugging level="0" />
<taskbegin task="Ping Scan" time="1422964867" />
<taskend task="Ping Scan" time="1422964867" extrainfo="1 total hosts" />
<taskbegin task="Parallel DNS resolution of 1 host." time="1422964867" />
<taskend task="Parallel DNS resolution of 1 host." time="1422964867" />
<taskbegin task="Traceroute" time="1422964867" />
<taskend task="Traceroute" time="1422964873" />
<host starttime="1422964867" endtime="1422964867"><status state="up" reason="reset"/>
<address addr="54.209.104.11" addrtype="ipv4" />
<hostnames>
<hostname name="ec2-54-209-104-11.compute-1.amazonaws.com" type="PTR"/>
</hostnames>
<trace port="80" proto="tcp">
<hop ttl="17" ipaddr="54.209.104.11" rtt="256.20" host="ec2-54-209-104-11.compute-1.amazonaws.com"/>
</trace>
<times srtt="256382" rttvar="192360" to="1025822" />
</host>
<runstats><finished time="1422964873" timestr="Tue Feb 3 12:01:13 2015" elapsed="6.48"/><hosts up="1" down="0" total="1" />
<!-- Nmap done at Tue Feb 3 12:01:13 2015; 1 IP address (1 host up) scanned in 6.48 seconds -->
</runstats></nmaprun>
我尝试使用Boost进行如下解析:
int main ( int, char ** )
try
{
// Will hold file contents.
stringstream contents;
// Open the file for the shortest time possible.
{ ifstream file("./SCB_nmap_tcp_traceroute.xml", ios::binary);
// Make sure we have something to read.
if ( !file.is_open() ) {
throw ("Could not open file.");
}
// Copy contents "as efficiently as possible".
contents << file.rdbuf();
}
// Do something "useful" with the file contents.
cout << contents.rdbuf();
using boost::property_tree::ptree;
ptree pt;
read_xml(contents, pt);
BOOST_FOREACH(ptree::value_type &v, pt.get_child("runstats"))
cout<<"Found trace"<<endl;
我正在获取一个没有这样的节点,通过BOOST_FOREACH为"nmaprun"、"trace"answers"runstats"转储核心。请提供建议。
在引发'boost::exception_detail::clone_inpl>'的实例后调用terminatewhat():没有这样的节点(runstats)中止(堆芯转储)
在您的定义中:
BOOST_FOREACH(ptree::value_type &v, pt.get_child("runstats"))
您需要将根节点放在runstats
之前,请尝试:
BOOST_FOREACH(ptree::value_type &v, pt.get_child("nmaprun.runstats"))
相关文章:
- boost xml parsingl将xml的路径作为变量发送
- boost::property_tree XML issue
- 如何使用 Boost XML 解析器
- Boost Read_graphml 无法正确读取 xml,它给出了所有顶点,但它们是空的
- Boost::p roperty_tree:在XML解析器中使用std::vector<>在一个键中存储多个值
- BOOST :: Archive :: XML_IARCHIVE带有XML(Deserizalisation Conte
- 如何将Boost属性树的子树序列化为XML
- 更改命名空间以自定义 Boost XML 的标记名称后的反序列化问题
- 使用 Boost c++ 解析嵌套标记的 xml
- Eclipse中的Boost TestRunner无法生成有效的XML
- boost::property_tree:复杂xml结构的解析
- 使用boost::property_tree编写CDATA XML节点
- 与boost::property_tree XML解析器一起使用时,boost::协同程序库崩溃
- 使用 Boost 属性树解析 SVG (XML)
- 如何使用 boost 的 ptree 删除 XML 的属性?
- 获取标签的子标签详细信息[BOOST PORPERTY_TREE XML]
- boost::p roperty_tree XML 漂亮的打印,格式化
- boost::spirit::xml::encode for wide string
- boost ptree的XML版本和编码
- boost属性树xml编写器输出没有结束