Is there a way to save the output of ip-scan executed from a script?
Add additional command argument as-value and output then can be passed to variable or other command argument. It will not be same output as printed on CLI, as-value returns key-value array, but that can be formatted for some file output if needed.
Thank you but I don’t know how to work with as-value.
I tried researching, but the explanations are of limited use.
Example:
:local filename "scan.txt"
:local records ""
:foreach scan in=[/tool/ip-scan duration=10s as-value] do={
:local record "IP: $($scan->"address"), MAC: $($scan->"mac-address")"
:put $record
:set records "$records$record\n"
}
:if ([:len records] > 0) do={
/file
:if ([:tobool [find where name=$filename]]) do={
remove $filename
}
add contents="IP scan records:\n$records" name=$filename
}
this will iterrate key-value array from command
/tool/ip-scan duration=10s as-value
result (modify this depending on your needs), print records in CLI and if records are populated (if ip-scan command did found some addresses) will save to (overwrite) file named in filename variable (scan.txt) with content header “IP scan records:\n” (you can change this in add contents=… command).
Key-value array from this ip-scan result can contain values in keys:
address
,
dns
,
mac-address
,
netbios
and
snmp
, you can modify record string variable in format depending on your needs and what you want to extract for each scan record (example uses only values from address and mac-address keys).