Multiple interfaces
This commit is contained in:
parent
415da92477
commit
09729acee7
5 changed files with 26 additions and 14 deletions
2
.github/workflows/docker-publish.yml
vendored
2
.github/workflows/docker-publish.yml
vendored
|
|
@ -14,7 +14,7 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IMAGE_NAME: watchyourlan
|
IMAGE_NAME: watchyourlan
|
||||||
TAGS: latest, v0.5
|
TAGS: latest, v0.6
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
# Ignore local data
|
# Ignore local data
|
||||||
data/
|
data/
|
||||||
watchyourlan
|
watchyourlan
|
||||||
|
tmp/
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# WatchYourLAN
|
# WatchYourLAN
|
||||||
|
|
||||||
[](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml)
|
[](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml)
|
||||||
|

|
||||||
|
|
||||||
Local network IP scanner with web gui
|
Local network IP scanner with web gui
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"log"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -11,11 +10,10 @@ import (
|
||||||
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 {
|
||||||
log.Fatal(err)
|
return string("")
|
||||||
|
} else {
|
||||||
|
return string(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(cmd)
|
|
||||||
// fmt.Println(text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse_output(text string) ([]Host) {
|
func parse_output(text string) ([]Host) {
|
||||||
|
|
@ -24,10 +22,10 @@ func parse_output(text string) ([]Host) {
|
||||||
perString := strings.Split(text, "\n")
|
perString := strings.Split(text, "\n")
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
|
|
||||||
for _, v := range perString {
|
for _, host := range perString {
|
||||||
if v != "" {
|
if host != "" {
|
||||||
var oneHost Host
|
var oneHost Host
|
||||||
p := strings.Split(v, " ")
|
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]
|
||||||
|
|
@ -38,5 +36,18 @@ func parse_output(text string) ([]Host) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundHosts
|
return foundHosts
|
||||||
// fmt.Println(foundHosts)
|
}
|
||||||
|
|
||||||
|
func arp_scan() ([]Host) {
|
||||||
|
var text string
|
||||||
|
var foundHosts = []Host{}
|
||||||
|
|
||||||
|
perString := strings.Split(AppConfig.Iface, " ")
|
||||||
|
|
||||||
|
for _, iface := range perString {
|
||||||
|
text = scan_iface(iface)
|
||||||
|
foundHosts = append(foundHosts, parse_output(text)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundHosts
|
||||||
}
|
}
|
||||||
|
|
@ -27,9 +27,9 @@ type Conf struct {
|
||||||
var AppConfig Conf
|
var AppConfig Conf
|
||||||
var AllHosts []Host
|
var AllHosts []Host
|
||||||
|
|
||||||
func scan() {
|
func scan_and_compare() {
|
||||||
for {
|
for {
|
||||||
foundHosts := parse_output(scan_iface(AppConfig.Iface))
|
foundHosts := arp_scan()
|
||||||
dbHosts := db_select()
|
dbHosts := db_select()
|
||||||
db_setnow()
|
db_setnow()
|
||||||
hosts_compare(foundHosts, dbHosts)
|
hosts_compare(foundHosts, dbHosts)
|
||||||
|
|
@ -45,8 +45,7 @@ func main() {
|
||||||
AppConfig = get_config("./data/config")
|
AppConfig = get_config("./data/config")
|
||||||
db_create()
|
db_create()
|
||||||
|
|
||||||
// fmt.Println("Timeout: ", AppConfig.Timeout)
|
go scan_and_compare()
|
||||||
go scan()
|
|
||||||
|
|
||||||
webgui()
|
webgui()
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue