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:
,
,
,
and
, 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).