Try arp-scan strings

This commit is contained in:
aceberg 2024-08-31 23:27:48 +07:00
parent 03846c4365
commit 7b45306415
6 changed files with 32 additions and 4 deletions

View file

@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.
## [v2.0.1] - 2024-08-31
### Changed
## [v2.0.0] - 2024-08-30
### Added
- API

View file

@ -16,7 +16,7 @@ func scanIface(iface string) string {
var cmd *exec.Cmd
if arpArgs != "" {
cmd = exec.Command("arp-scan", arpArgs, "-I", iface)
cmd = exec.Command("arp-scan", "-glNx", arpArgs, "-I", iface)
} else {
cmd = exec.Command("arp-scan", "-glNx", "-I", iface)
}
@ -29,6 +29,20 @@ func scanIface(iface string) string {
return string(out)
}
func scanStr(str string) string {
args := strings.Split(str, " ")
cmd := exec.Command("arp-scan", args...)
out, err := cmd.Output()
slog.Debug(cmd.String())
if check.IfError(err) {
return string("")
}
return string(out)
}
func parseOutput(text, iface string) []models.Host {
var foundHosts = []models.Host{}
@ -52,7 +66,7 @@ func parseOutput(text, iface string) []models.Host {
}
// Scan all interfaces
func Scan(ifaces, args string) []models.Host {
func Scan(ifaces, args string, strs []string) []models.Host {
var text string
var foundHosts = []models.Host{}
arpArgs = args
@ -67,5 +81,13 @@ func Scan(ifaces, args string) []models.Host {
foundHosts = append(foundHosts, parseOutput(text, iface)...)
}
for _, s := range strs {
slog.Debug("Scanning string " + s)
text = scanStr(s)
slog.Debug("Found IPs: \n" + text)
foundHosts = append(foundHosts, parseOutput(text, "")...)
}
return foundHosts
}

View file

@ -42,6 +42,7 @@ func Get(path string) (config models.Conf) {
config.NodePath = viper.Get("NODEPATH").(string)
config.LogLevel = viper.Get("LOG_LEVEL").(string)
config.ArpArgs = viper.Get("ARP_ARGS").(string)
config.ArpStrs = viper.GetStringSlice("ARP_STRS")
config.Ifaces = viper.Get("IFACES").(string)
config.Timeout = viper.GetInt("TIMEOUT")
config.TrimHist = viper.GetInt("TRIM_HIST")
@ -74,6 +75,7 @@ func Write(config models.Conf) {
viper.Set("NODEPATH", config.NodePath)
viper.Set("LOG_LEVEL", config.LogLevel)
viper.Set("ARP_ARGS", config.ArpArgs)
viper.Set("ARP_STRS", config.ArpStrs)
viper.Set("IFACES", config.Ifaces)
viper.Set("TIMEOUT", config.Timeout)
viper.Set("TRIM_HIST", config.TrimHist)

View file

@ -13,6 +13,7 @@ type Conf struct {
LogLevel string
Ifaces string
ArpArgs string
ArpStrs []string
Timeout int
TrimHist int
HistInDB bool

View file

@ -1 +1 @@
VERSION=2.0.0
VERSION=2.0.1

View file

@ -26,7 +26,7 @@ func startScan(quit chan bool) {
if nowDate.After(plusDate) {
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs)
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs, appConfig.ArpStrs)
compareHosts(foundHosts)
allHosts = db.Select("now")