aceberg / WatchYourLAN

Lightweight network IP scanner. Can be used to notify about new hosts and monitor host online/offline history
https://hub.docker.com/r/aceberg/watchyourlan
MIT License
3.84k stars 119 forks source link

Feature Request: Scan VLAN subnets #47

Closed thehijacker closed 1 month ago

thehijacker commented 1 year ago

Looking for alternative to PiAlert. This looks like much simpler version of it with simillar features. But one is missing that I need so I can capture all my subnets. Arp-scan can also scan VLAN subnets with syntax:

arp-scan --ignoredups --retry=6 10.0.107.0/24 -vlan=107 --interface=eth0

Can this vlan parameter be added as well as option to scan multiple subnets?

Thank you.

thehijacker commented 1 year ago

I made some changes to the internal/scan/arpscan.go:

-func scanIface(iface string) string {
+func scanIface(iface []string) string {
-        cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
+       cmd, err := exec.Command("arp-scan", iface...).Output()
        if err != nil {
                return string("")
        }
        return string(cmd)
}
// Scan all interfaces
func arpScan(allIfaces string) []models.Host {
        var text string
        var foundHosts = []models.Host{}

        perString := strings.Split(allIfaces, ",")

        for _, iface := range perString {
                log.Println("INFO: scanning interface", iface)
-                 text = scanIface(iface)
+                text = scanIface(strings.Split("-gNx " + strings.TrimSpace(iface), " "))
                log.Println("INFO: found IPs:", text)
                foundHosts = append(foundHosts, parseOutput(text)...)
        }

        return foundHosts
}

Basically the parameters can be anything and it will pass them as array of parameters. For example:

IFACE=-l -I vmbr0, 10.0.208.0/24 -Q 208 -I vmbr0, 10.0.107.0/24 -Q 107 -I vmbr0

or long syntax

IFACE=-l --interface=vmbr0, 10.0.208.0/24 --vlan=208 --interface=vmbr0, 10.0.107.0/24 --vlan=107 --interface=vmbr0

Using this changes and IFACE parameters, all three of my home networks are scanned. Could this be included in next version? Or possible improved. First time I looked at a go code :)

Next I need to figure out how to put this new binary inside my docker container.

GentleHoneyLover commented 1 year ago

+1 for the feature. Segmented my network into VLANs recently and realized that WatchYourLAN can only see within its subnet...

lima3w commented 1 year ago

Just set up an instance myself and noticed there wasnt an option for specifying what subnets to scan. I have a few subnets, based on wifi, homelab, hardwire, guest, iot devices, etc. I dont want to have to run an instance for each.

+1 for this

hobybrenner commented 1 year ago

Multiple subnets/vlans would be wonderful!

dustingrady commented 5 months ago

Agreed. I just tried this (and the various forks of Pi Alert) trying to find one that would work for my multi-VLAN setup. This feature would be amazing.

Jffrey commented 4 months ago

This feature would be awsome! sadly im not a dev and cant help :(

I will try to get my head into how to fix that like @thehijacker advertised, maybe you could provide a little guide for non devs?

thx in advance

aceberg commented 1 month ago

Done in v2.0.1 - see docs/VLAN_ARP_SCAN.md for a howto.