forked from mostlygeek/arp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharp.go
More file actions
49 lines (40 loc) · 669 Bytes
/
arp.go
File metadata and controls
49 lines (40 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package arp
import (
"time"
)
type ArpTable map[string]string
var (
stop = make(chan struct{})
arpCache = &cache{
table: make(ArpTable),
}
)
func AutoRefresh(t time.Duration) {
go func() {
for {
select {
case <-time.After(t):
arpCache.Refresh()
case <-stop:
return
}
}
}()
}
func StopAutoRefresh() {
stop <- struct{}{}
}
func CacheUpdate() {
arpCache.Refresh()
}
func CacheLastUpdate() time.Time {
return arpCache.Updated
}
func CacheUpdateCount() int {
return arpCache.UpdatedCount
}
// Search looks up the MAC address for an IP address
// in the arp table
func Search(ip string) string {
return arpCache.Search(ip)
}