Try arp-scan strings
This commit is contained in:
parent
03846c4365
commit
7b45306415
6 changed files with 32 additions and 4 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## [v2.0.0] - 2024-08-30
|
||||||
### Added
|
### Added
|
||||||
- API
|
- API
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func scanIface(iface string) string {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
|
|
||||||
if arpArgs != "" {
|
if arpArgs != "" {
|
||||||
cmd = exec.Command("arp-scan", arpArgs, "-I", iface)
|
cmd = exec.Command("arp-scan", "-glNx", arpArgs, "-I", iface)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command("arp-scan", "-glNx", "-I", iface)
|
cmd = exec.Command("arp-scan", "-glNx", "-I", iface)
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,20 @@ func scanIface(iface string) string {
|
||||||
return string(out)
|
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 {
|
func parseOutput(text, iface string) []models.Host {
|
||||||
var foundHosts = []models.Host{}
|
var foundHosts = []models.Host{}
|
||||||
|
|
||||||
|
|
@ -52,7 +66,7 @@ func parseOutput(text, iface string) []models.Host {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan all interfaces
|
// Scan all interfaces
|
||||||
func Scan(ifaces, args string) []models.Host {
|
func Scan(ifaces, args string, strs []string) []models.Host {
|
||||||
var text string
|
var text string
|
||||||
var foundHosts = []models.Host{}
|
var foundHosts = []models.Host{}
|
||||||
arpArgs = args
|
arpArgs = args
|
||||||
|
|
@ -67,5 +81,13 @@ func Scan(ifaces, args string) []models.Host {
|
||||||
foundHosts = append(foundHosts, parseOutput(text, iface)...)
|
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
|
return foundHosts
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ func Get(path string) (config models.Conf) {
|
||||||
config.NodePath = viper.Get("NODEPATH").(string)
|
config.NodePath = viper.Get("NODEPATH").(string)
|
||||||
config.LogLevel = viper.Get("LOG_LEVEL").(string)
|
config.LogLevel = viper.Get("LOG_LEVEL").(string)
|
||||||
config.ArpArgs = viper.Get("ARP_ARGS").(string)
|
config.ArpArgs = viper.Get("ARP_ARGS").(string)
|
||||||
|
config.ArpStrs = viper.GetStringSlice("ARP_STRS")
|
||||||
config.Ifaces = viper.Get("IFACES").(string)
|
config.Ifaces = viper.Get("IFACES").(string)
|
||||||
config.Timeout = viper.GetInt("TIMEOUT")
|
config.Timeout = viper.GetInt("TIMEOUT")
|
||||||
config.TrimHist = viper.GetInt("TRIM_HIST")
|
config.TrimHist = viper.GetInt("TRIM_HIST")
|
||||||
|
|
@ -74,6 +75,7 @@ func Write(config models.Conf) {
|
||||||
viper.Set("NODEPATH", config.NodePath)
|
viper.Set("NODEPATH", config.NodePath)
|
||||||
viper.Set("LOG_LEVEL", config.LogLevel)
|
viper.Set("LOG_LEVEL", config.LogLevel)
|
||||||
viper.Set("ARP_ARGS", config.ArpArgs)
|
viper.Set("ARP_ARGS", config.ArpArgs)
|
||||||
|
viper.Set("ARP_STRS", config.ArpStrs)
|
||||||
viper.Set("IFACES", config.Ifaces)
|
viper.Set("IFACES", config.Ifaces)
|
||||||
viper.Set("TIMEOUT", config.Timeout)
|
viper.Set("TIMEOUT", config.Timeout)
|
||||||
viper.Set("TRIM_HIST", config.TrimHist)
|
viper.Set("TRIM_HIST", config.TrimHist)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ type Conf struct {
|
||||||
LogLevel string
|
LogLevel string
|
||||||
Ifaces string
|
Ifaces string
|
||||||
ArpArgs string
|
ArpArgs string
|
||||||
|
ArpStrs []string
|
||||||
Timeout int
|
Timeout int
|
||||||
TrimHist int
|
TrimHist int
|
||||||
HistInDB bool
|
HistInDB bool
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
VERSION=2.0.0
|
VERSION=2.0.1
|
||||||
|
|
@ -26,7 +26,7 @@ func startScan(quit chan bool) {
|
||||||
|
|
||||||
if nowDate.After(plusDate) {
|
if nowDate.After(plusDate) {
|
||||||
|
|
||||||
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs)
|
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs, appConfig.ArpStrs)
|
||||||
compareHosts(foundHosts)
|
compareHosts(foundHosts)
|
||||||
allHosts = db.Select("now")
|
allHosts = db.Select("now")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue