Refactor stations discovery and add hostapd discovery
This commit is contained in:
parent
69594c2fe4
commit
2922a03724
15 changed files with 1339 additions and 249 deletions
64
internal/station/arp/parser.go
Normal file
64
internal/station/arp/parser.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package arp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ARPEntry represents an entry in the ARP table
|
||||
type ARPEntry struct {
|
||||
IP net.IP
|
||||
HWType int
|
||||
Flags int
|
||||
HWAddress net.HardwareAddr
|
||||
Mask string
|
||||
Device string
|
||||
}
|
||||
|
||||
// parseARPTable reads and parses ARP table from /proc/net/arp format
|
||||
func parseARPTable(path string) ([]ARPEntry, error) {
|
||||
var entries []ARPEntry
|
||||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return entries, err
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(content), "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) > 5 {
|
||||
var entry ARPEntry
|
||||
|
||||
// Parse HWType (hex format)
|
||||
if _, err := fmt.Sscanf(fields[1], "0x%x", &entry.HWType); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse Flags (hex format)
|
||||
if _, err := fmt.Sscanf(fields[2], "0x%x", &entry.Flags); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse IP address
|
||||
entry.IP = net.ParseIP(fields[0])
|
||||
if entry.IP == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse MAC address
|
||||
entry.HWAddress, err = net.ParseMAC(fields[3])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
entry.Mask = fields[4]
|
||||
entry.Device = fields[5]
|
||||
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
}
|
||||
|
||||
return entries, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue