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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type Conf struct {
|
|||
LogLevel string
|
||||
Ifaces string
|
||||
ArpArgs string
|
||||
ArpStrs []string
|
||||
Timeout int
|
||||
TrimHist int
|
||||
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) {
|
||||
|
||||
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs)
|
||||
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs, appConfig.ArpStrs)
|
||||
compareHosts(foundHosts)
|
||||
allHosts = db.Select("now")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue