Feature/multithreaded_arpscan :: Made ARP Scan run in multiple threads to speed up detection
This commit is contained in:
parent
0c49949a5d
commit
a0470760a9
1 changed files with 48 additions and 39 deletions
|
|
@ -4,10 +4,11 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scan_iface(iface string) (string) {
|
func scan_iface(iface string) string {
|
||||||
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return string("")
|
return string("")
|
||||||
|
|
@ -16,7 +17,7 @@ func scan_iface(iface string) (string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse_output(text string) ([]Host) {
|
func parse_output(text string) []Host {
|
||||||
var foundHosts = []Host{}
|
var foundHosts = []Host{}
|
||||||
|
|
||||||
perString := strings.Split(text, "\n")
|
perString := strings.Split(text, "\n")
|
||||||
|
|
@ -38,18 +39,26 @@ func parse_output(text string) ([]Host) {
|
||||||
return foundHosts
|
return foundHosts
|
||||||
}
|
}
|
||||||
|
|
||||||
func arp_scan() ([]Host) {
|
func arp_scan() []Host {
|
||||||
var text string
|
|
||||||
var foundHosts = []Host{}
|
var foundHosts = []Host{}
|
||||||
|
|
||||||
perString := strings.Split(AppConfig.Iface, " ")
|
perString := strings.Split(AppConfig.Iface, " ")
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(len(perString))
|
||||||
|
arpScanMutex := &sync.Mutex{}
|
||||||
|
|
||||||
for _, iface := range perString {
|
for _, iface := range perString {
|
||||||
log.Println("INFO: scanning interface", iface)
|
// Multi thread arp-scan
|
||||||
text = scan_iface(iface)
|
go func(thisInterface string) {
|
||||||
|
log.Println("INFO: scanning interface", thisInterface)
|
||||||
|
text := scan_iface(thisInterface)
|
||||||
log.Println("INFO: found IPs:", text)
|
log.Println("INFO: found IPs:", text)
|
||||||
foundHosts = append(foundHosts, parse_output(text)...)
|
parsedHosts := parse_output(text)
|
||||||
|
arpScanMutex.Lock()
|
||||||
|
foundHosts = append(foundHosts, parsedHosts...)
|
||||||
|
arpScanMutex.Unlock()
|
||||||
|
wg.Done()
|
||||||
|
}(iface)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
return foundHosts
|
return foundHosts
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue