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
|
|
@ -1,55 +1,64 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func scan_iface(iface string) (string) {
|
||||
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
||||
if err != nil {
|
||||
return string("")
|
||||
} else {
|
||||
return string(cmd)
|
||||
}
|
||||
func scan_iface(iface string) string {
|
||||
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
||||
if err != nil {
|
||||
return string("")
|
||||
} else {
|
||||
return string(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
func parse_output(text string) ([]Host) {
|
||||
var foundHosts = []Host{}
|
||||
func parse_output(text string) []Host {
|
||||
var foundHosts = []Host{}
|
||||
|
||||
perString := strings.Split(text, "\n")
|
||||
perString := strings.Split(text, "\n")
|
||||
currentTime := time.Now()
|
||||
|
||||
for _, host := range perString {
|
||||
if host != "" {
|
||||
var oneHost Host
|
||||
p := strings.Split(host, " ")
|
||||
oneHost.Ip = p[0]
|
||||
oneHost.Mac = p[1]
|
||||
oneHost.Hw = p[2]
|
||||
for _, host := range perString {
|
||||
if host != "" {
|
||||
var oneHost Host
|
||||
p := strings.Split(host, " ")
|
||||
oneHost.Ip = p[0]
|
||||
oneHost.Mac = p[1]
|
||||
oneHost.Hw = p[2]
|
||||
oneHost.Date = currentTime.Format("2006-01-02 15:04:05")
|
||||
oneHost.Now = 1
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
}
|
||||
}
|
||||
oneHost.Now = 1
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
}
|
||||
}
|
||||
|
||||
return foundHosts
|
||||
return foundHosts
|
||||
}
|
||||
|
||||
func arp_scan() ([]Host) {
|
||||
var text string
|
||||
var foundHosts = []Host{}
|
||||
func arp_scan() []Host {
|
||||
var foundHosts = []Host{}
|
||||
perString := strings.Split(AppConfig.Iface, " ")
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(perString))
|
||||
arpScanMutex := &sync.Mutex{}
|
||||
|
||||
perString := strings.Split(AppConfig.Iface, " ")
|
||||
|
||||
for _, iface := range perString {
|
||||
log.Println("INFO: scanning interface", iface)
|
||||
text = scan_iface(iface)
|
||||
log.Println("INFO: found IPs:", text)
|
||||
foundHosts = append(foundHosts, parse_output(text)...)
|
||||
}
|
||||
|
||||
return foundHosts
|
||||
}
|
||||
for _, iface := range perString {
|
||||
// Multi thread arp-scan
|
||||
go func(thisInterface string) {
|
||||
log.Println("INFO: scanning interface", thisInterface)
|
||||
text := scan_iface(thisInterface)
|
||||
log.Println("INFO: found IPs:", 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