From d72349e63fe18c534df556f94e78b3979d526b1d Mon Sep 17 00:00:00 2001 From: Shannon Haworth Date: Sat, 6 Oct 2018 23:38:17 -0400 Subject: [PATCH] Update arp.go Added SearchByMac which returns the IP Address for a given MAC Address --- arp.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arp.go b/arp.go index a4958ec..0dadd8d 100644 --- a/arp.go +++ b/arp.go @@ -2,6 +2,7 @@ package arp import ( "time" + "errors" ) type ArpTable map[string]string @@ -47,3 +48,15 @@ func CacheUpdateCount() int { func Search(ip string) string { return arpCache.Search(ip) } + +// Search looks up the IP address by MAC address +// in the arp table +func SearchByMac(target string) (string, error) { + for ip, _ := range Table() { + m := Search(ip) + if(m == target) { + return ip, nil + } + } + return "", errors.New("Mac not found") +}