Parsing XML with Powershell...
so xml report nmap:
<?xml version="1.0" encoding="utf-8" ?>
<nmaprun scanner="nmap" args="nmap -f --script=smb-os-discovery --script=nbstat -ox c:\\nmap\\temp2\\result3.xml 1.1.1.1" start="1327070530" startstr="fri jan 20 09:42:10 2012" version="5.51" xmloutputversion="1.03">
<scaninfo type="syn" protocol="tcp" numservices="100" />
<verbose level="0" />
<debugging level="0" />
<status state="up" reason="echo-reply" />
<address addr="1.1.1.1" addrtype="ipv4" />
<hostname name="test.test.com" type="ptr" />
</hostnames>
<script id="nbstat" output="netbios name: test, netbios user: <unknown>, netbios mac: 00:00:00:00:00:00 (usi) names of060l3a0760x<00> flags: <unique><active> of060l3a0760x<20> flags: <unique><active> test<00> flags: <group><active> test<1e> flags: <group><active> test<1d> flags: <unique><active> \x01\x02__msbrowse__\x02<01> flags: <group><active>" />
<script id="smb-os-discovery" output="os: windows xp (windows 2000 lan manager) name: test\test system time: 2012-01-20 09:41:19 utc-5" />
</hostscript>
i know how to information nmarun.host.hostscript.script.output, need mac, os , name nothing else..... , somehow create table 3 items , | export-csv
thanks in advance
[xml]$xml = get-content c__nmap_temp2_result3.xml $hosts = $xml.nmaprun.host $result = @() foreach ($i in $hosts) { foreach ($j in $i | foreach {$_.hostscript}) { $data = $j.script | foreach {$_.output} $data[0] -match "mac: (?<mac>[0-9a-f:]+)" | out-null $mac = $matches.mac $data[1] -match "(?s).+os: (?<os>.+).+name: (?<name>.+)\b.+system" | out-null $result += new-object psobject -property @{ name = $matches.name ipv4 = $i.address.addr mac = $mac os = $matches.os.trim() } } } $result
Windows Server > Windows PowerShell
Comments
Post a Comment