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
|
package main
|
||||||
|
|
||||||
import (
|
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("")
|
||||||
} else {
|
} else {
|
||||||
return string(cmd)
|
return string(cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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")
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
|
|
||||||
for _, host := range perString {
|
for _, host := range perString {
|
||||||
if host != "" {
|
if host != "" {
|
||||||
var oneHost Host
|
var oneHost Host
|
||||||
p := strings.Split(host, " ")
|
p := strings.Split(host, " ")
|
||||||
oneHost.Ip = p[0]
|
oneHost.Ip = p[0]
|
||||||
oneHost.Mac = p[1]
|
oneHost.Mac = p[1]
|
||||||
oneHost.Hw = p[2]
|
oneHost.Hw = p[2]
|
||||||
oneHost.Date = currentTime.Format("2006-01-02 15:04:05")
|
oneHost.Date = currentTime.Format("2006-01-02 15:04:05")
|
||||||
oneHost.Now = 1
|
oneHost.Now = 1
|
||||||
foundHosts = append(foundHosts, oneHost)
|
foundHosts = append(foundHosts, oneHost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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, " ")
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(len(perString))
|
||||||
|
arpScanMutex := &sync.Mutex{}
|
||||||
|
|
||||||
perString := strings.Split(AppConfig.Iface, " ")
|
for _, iface := range perString {
|
||||||
|
// Multi thread arp-scan
|
||||||
for _, iface := range perString {
|
go func(thisInterface string) {
|
||||||
log.Println("INFO: scanning interface", iface)
|
log.Println("INFO: scanning interface", thisInterface)
|
||||||
text = scan_iface(iface)
|
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...)
|
||||||
return foundHosts
|
arpScanMutex.Unlock()
|
||||||
|
wg.Done()
|
||||||
|
}(iface)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return foundHosts
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue