Args for arp-scan
This commit is contained in:
parent
9aa39c471e
commit
1ab69ba1ea
5 changed files with 35 additions and 13 deletions
|
|
@ -6,15 +6,27 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aceberg/WatchYourLAN/internal/check"
|
||||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var arpArgs string
|
||||||
|
|
||||||
func scanIface(iface string) string {
|
func scanIface(iface string) string {
|
||||||
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
|
var cmd *exec.Cmd
|
||||||
if err != nil {
|
|
||||||
|
if arpArgs != "" {
|
||||||
|
cmd = exec.Command("arp-scan", "-glNx", arpArgs, "-I", iface)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("arp-scan", "-glNx", "-I", iface)
|
||||||
|
}
|
||||||
|
out, err := cmd.Output()
|
||||||
|
slog.Debug(cmd.String())
|
||||||
|
|
||||||
|
if check.IfError(err) {
|
||||||
return string("")
|
return string("")
|
||||||
}
|
}
|
||||||
return string(cmd)
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseOutput(text, iface string) []models.Host {
|
func parseOutput(text, iface string) []models.Host {
|
||||||
|
|
@ -40,16 +52,16 @@ func parseOutput(text, iface string) []models.Host {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan all interfaces
|
// Scan all interfaces
|
||||||
func Scan(ifaces string) []models.Host {
|
func Scan(ifaces, args string) []models.Host {
|
||||||
var text string
|
var text string
|
||||||
var foundHosts = []models.Host{}
|
var foundHosts = []models.Host{}
|
||||||
|
arpArgs = args
|
||||||
|
|
||||||
perString := strings.Split(ifaces, " ")
|
perString := strings.Split(ifaces, " ")
|
||||||
|
|
||||||
for _, iface := range perString {
|
for _, iface := range perString {
|
||||||
text = scanIface(iface)
|
|
||||||
|
|
||||||
slog.Debug("Scanning interface " + iface)
|
slog.Debug("Scanning interface " + iface)
|
||||||
|
text = scanIface(iface)
|
||||||
slog.Debug("Found IPs: \n" + text)
|
slog.Debug("Found IPs: \n" + text)
|
||||||
|
|
||||||
foundHosts = append(foundHosts, parseOutput(text, iface)...)
|
foundHosts = append(foundHosts, parseOutput(text, iface)...)
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ func SetCurrent(config models.Conf) {
|
||||||
currentDB.SQLitePath = config.DBPath
|
currentDB.SQLitePath = config.DBPath
|
||||||
currentDB.PGConnect = config.PGConnect
|
currentDB.PGConnect = config.PGConnect
|
||||||
|
|
||||||
if currentDB.Use == "postgres" {
|
if currentDB.Use == "postgres" && currentDB.PGConnect != "" {
|
||||||
currentDB.PrimaryKey = "BIGSERIAL PRIMARY KEY"
|
currentDB.PrimaryKey = "BIGSERIAL PRIMARY KEY"
|
||||||
} else {
|
} else {
|
||||||
|
currentDB.Use = "sqlite"
|
||||||
currentDB.PrimaryKey = "INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE"
|
currentDB.PrimaryKey = "INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
|
|
@ -17,7 +17,11 @@ func dbExecPG(sqlStatement string) {
|
||||||
// slog.Debug("PG Exec " + sqlStatement)
|
// slog.Debug("PG Exec " + sqlStatement)
|
||||||
|
|
||||||
db, err := sqlx.Connect("postgres", currentDB.PGConnect)
|
db, err := sqlx.Connect("postgres", currentDB.PGConnect)
|
||||||
check.IfError(err)
|
if check.IfError(err) {
|
||||||
|
slog.Warn("PostgreSQL connection error. Falling back to SQLite.")
|
||||||
|
currentDB.Use = "sqlite"
|
||||||
|
Create()
|
||||||
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(sqlStatement)
|
_, err = db.Exec(sqlStatement)
|
||||||
|
|
@ -30,10 +34,15 @@ func selectPG(table string) (dbHosts []models.Host) {
|
||||||
|
|
||||||
// slog.Debug("PG Select " + sqlStatement)
|
// slog.Debug("PG Select " + sqlStatement)
|
||||||
|
|
||||||
db, _ := sqlx.Connect("postgres", currentDB.PGConnect)
|
db, err := sqlx.Connect("postgres", currentDB.PGConnect)
|
||||||
|
if check.IfError(err) {
|
||||||
|
slog.Warn("PostgreSQL connection error. Falling back to SQLite.")
|
||||||
|
currentDB.Use = "sqlite"
|
||||||
|
Create()
|
||||||
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
err := db.Select(&dbHosts, sqlStatement)
|
err = db.Select(&dbHosts, sqlStatement)
|
||||||
check.IfError(err)
|
check.IfError(err)
|
||||||
|
|
||||||
return dbHosts
|
return dbHosts
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ func startScan(quit chan bool) {
|
||||||
|
|
||||||
if nowDate.After(plusDate) {
|
if nowDate.After(plusDate) {
|
||||||
|
|
||||||
foundHosts = arp.Scan(appConfig.Ifaces)
|
foundHosts = arp.Scan(appConfig.Ifaces, appConfig.ArpArgs)
|
||||||
compareHosts(foundHosts)
|
compareHosts(foundHosts)
|
||||||
allHosts = db.Select("now")
|
allHosts = db.Select("now")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
<td><input name="timeout" type="number" class="form-control" value="{{ .Config.Timeout }}"></td>
|
<td><input name="timeout" type="number" class="form-control" value="{{ .Config.Timeout }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Args for arpscan</td>
|
<td>Args for arp-scan</td>
|
||||||
<td><input name="arpargs" type="text" class="form-control" value="{{ .Config.ArpArgs }}"></td>
|
<td><input name="arpargs" type="text" class="form-control" value="{{ .Config.ArpArgs }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue