infra/tnoe/tnoescan-masscan.spl

108 lines
2.3 KiB
Text
Raw Normal View History

2024-11-22 14:06:33 +01:00
"#time.spl" import
"#stream.spl" import
"#json.spl" import
include json:_StringyJSON in array
include json:_StringyJSON in str
func main { exitcode | with args ;
"scanning network " print args:2 println
def nmap
[ "sudo" "masscan" "--rate" "1000" "--ping" "--wait" "2" args:2 ] StreamTypes:cmd:create =nmap
nmap:read-to-end<1024> _str =nmap
nmap:split<"\n">:iter =nmap
def records, line
[ ] =records
while { nmap:next dup =line } {
line:readf1<"Discovered open port 0/icmp on {} {}"> => &=line if {
line awrap records swap aadd =records
2 stop
}
} pop
"IPs: " println
records:foreach<| ("IP: " print) :sjson println>
"waiting..." println
3000 time:sleep;
"grabbing MACs+Hostnames" println
def i 0 =i
def newrecords
[ ] =newrecords
def running [ 0 0 0 0 0 ] =running
while { i records:len lt } {
"task " print i println
while { running:contains<0> not } {
500 time:sleep;
}
running:find<0 awrap> i fork<| with id i ;
1 id running:set;
def done [ ] =done
def nmap, out, line, ip, hostname
[ "sudo" "nmap" "-T4" "-sn" records:get<i> ] StreamTypes:cmd:create =nmap
nmap:read-to-end<1024> _str =out
[ "sudo" "nmap" "-sn" "-Pn" records:get<i> ] StreamTypes:cmd:create =nmap
out nmap:read-to-end<1024> _str concat =nmap
func submit { | with mac ;
0 done:foreach<| ip eq if { pop 1 }> not if {
done ip awrap aadd =done
newrecords [ ip hostname mac ] awrap aadd =newrecords
}
null =ip
}
nmap:split<"\n">:iter =nmap
while { nmap:next dup =line } {
line:readf<"Nmap scan report for {} ({})"> => &=line if {
ip null eq not if {
"?" submit
}
line:0 =hostname
line:1 =ip
2 stop
}
line:readf1<"Nmap scan report for {}"> => &=ip if {
"?" =hostname
2 stop
}
line:readf1<"MAC Address: {} ({})"> => &=line if {
line submit
2 stop
}
} pop
ip null eq not hostname "?" eq not and if {
"?" submit
}
0 id running:set;
> pop pop
100 time:sleep;
i ++ =i
}
while { running:contains<1> } {
500 time:sleep;
}
newrecords:foreach<| ("Record: " print) :sjson println>
"Success rate: " print newrecords:len _float records:len _float / 100 _float * print "%" println
0
}
func min { min(a,b) | with a b ;
a
a b gt if {
pop b
}
}