func main() { fmt.Println("Get local ips from interfaces...") addr_interfaces := utils.LocalAddresses() devices_interfaces := []device.Device{} for _, a := range addr_interfaces { fmt.Printf("Get ips for %v network...\n", a) ips_on_network, _ := utils.IPS_Network(a.String()) for _, ip := range ips_on_network { info := device.Device{} info.SetIP(ip) fmt.Printf("scanning %s...\n", ip) if !device.DeviceInSlice(info, devices_interfaces) { devices_interfaces = append(devices_interfaces, info) } } } arp_table := arp.ArpTable{} scanning(&arp_table) fmt.Println("Search duplicates...") devices := device.DeviceJoinSlice(arp_table.Devices, devices_interfaces) print_devices(devices) }
func (table *ArpTable) Read() { f, err := os.Open("/proc/net/arp") if err != nil { table.Devices = nil } defer f.Close() s := bufio.NewScanner(f) s.Scan() // skip the field descriptions for s.Scan() { line := s.Text() fields := strings.Fields(line) info := device.Device{ HWAddr: fields[f_HWAddr], } info.SetIP(fields[f_IPAddr]) table.Add(info) } }