infra/tnoe/tnoescan.spl

32 lines
729 B
Text

"#stream.spl" import
"#json.spl" import
include json:_StringyJSON in array
func main { exitcode | with args ;
"scanning network " print args:2 println
def nmap
[ "sudo" "nmap" "-T5" "-sn" args:2 ] StreamTypes:cmd:create =nmap
nmap:read-to-end<1024> _str =nmap
nmap:split<"\n">:iter =nmap
def records, hostname, ip, line
[ ] =records
while { nmap:next dup =line } {
line:readf<"Nmap scan report for {} ({})"> => [ &=hostname &=ip ] if {
2 stop
} pop
line:readf1<"Nmap scan report for {}"> => &=ip if {
"?" =hostname
2 stop
} pop
line:readf1<"MAC Address: {} ({})"> => &=line if {
records [ ip hostname line ] awrap aadd =records
2 stop
} pop
} pop
records:foreach<| :sjson println>
0
}