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"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func scan_iface(iface string) (string) {
|
||||
func scan_iface(iface string) string {
|
||||
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
||||
if err != nil {
|
||||
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{}
|
||||
|
||||
perString := strings.Split(text, "\n")
|
||||
|
|
@ -38,18 +39,26 @@ func parse_output(text string) ([]Host) {
|
|||
return foundHosts
|
||||
}
|
||||
|
||||
func arp_scan() ([]Host) {
|
||||
var text string
|
||||
func arp_scan() []Host {
|
||||
var foundHosts = []Host{}
|
||||
|
||||
perString := strings.Split(AppConfig.Iface, " ")
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(perString))
|
||||
arpScanMutex := &sync.Mutex{}
|
||||
|
||||
for _, iface := range perString {
|
||||
log.Println("INFO: scanning interface", iface)
|
||||
text = scan_iface(iface)
|
||||
// Multi thread arp-scan
|
||||
go func(thisInterface string) {
|
||||
log.Println("INFO: scanning interface", thisInterface)
|
||||
text := scan_iface(thisInterface)
|
||||
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
|
||||
}
|
||||
Loading…
Reference in a new issue