package asaModels import ( "regexp" "strconv" "strings" ) var arpRE = regexp.MustCompile(`(\S+)[ ](\S+)[ ](\S+)[ ]([0-9]+)`) type ( ARPCache struct { ARPList []*ARPEntry `json:"arp_table"` } ARPEntry struct { Address string `json:"address"` IfName string `json:"if_name"` Mac string `json:"mac_address"` TimeOut int `json:"timeout"` } ) // Function to parse ASA show arp output func (a *ARPCache) Parse(s string) { for _, v := range arpRE.FindAllStringSubmatch(s, -1) { a.ARPList = append(a.ARPList, &ARPEntry{ Address: v[2], IfName: v[1], Mac: v[3], TimeOut: func() int { if i, err := strconv.Atoi(v[4]); err == nil { return i } return 0 }(), }) } } // Function to find an IP address func (a *ARPCache) FindIP4(ip string) *ARPEntry { return FindIP4(ip, a.ARPList) } func FindIP4(ip string, arp []*ARPEntry) *ARPEntry { for _, e := range arp { if ip == e.Address { return e } } return nil } // Function to fina a MAC address, returns a list of matching entries func (a *ARPCache) FindMAC(mac string) []*ARPEntry { return FindMAC(mac, a.ARPList) } func FindMAC(mac string, arp []*ARPEntry) (a []*ARPEntry) { mac = strings.ToLower(mac) for _, e := range arp { if mac == strings.ToLower(e.Mac) { a = append(a, e) } } return a }