-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacmap.go
More file actions
68 lines (55 loc) · 1.47 KB
/
macmap.go
File metadata and controls
68 lines (55 loc) · 1.47 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package macmap
import "C"
import (
"fmt"
"os"
"path"
"runtime"
"strings"
)
var db24 map[string]interface{}
var db28 map[string]interface{}
var db36 map[string]interface{}
func init() {
_, file, _, _ := runtime.Caller(0)
f24Name := path.Join(path.Dir(file), "MAS.csv")
f28Name := path.Join(path.Dir(file), "MAM.csv")
f36Name := path.Join(path.Dir(file), "MAL.csv")
f24, _ := os.Open(f24Name)
f28, _ := os.Open(f28Name)
f36, _ := os.Open(f36Name)
defer f24.Close()
defer f28.Close()
defer f36.Close()
reader24 := NewReader(f24)
reader28 := NewReader(f28)
reader36 := NewReader(f36)
_, _ = reader24.GetFieldNames()
db24, _ = reader24.ReadAll2Map("Assignment")
db28, _ = reader28.ReadAll2Map("Assignment")
db36, _ = reader36.ReadAll2Map("Assignment")
}
func Search(mac string) (info string) {
var bit24, bit28, bit36 int = 24, 28, 36
strSlice := strings.Split(mac, ":")
macStr := strings.Join(strSlice, "")
index24 := strings.ToUpper(macStr[0 : bit24/4])
index28 := strings.ToUpper(macStr[0 : bit28/4])
index36 := strings.ToUpper(macStr[0 : bit36/4])
var vendorInfo interface{} = nil
if info1, ok := db24[index24]; ok {
if info2, ok := db28[index28]; ok {
if info3, ok := db36[index36]; ok {
vendorInfo = info3
}
vendorInfo = info2
}
vendorInfo = info1
}
if vendorInfo == nil {
return ""
}
vendorInfoSlice := make([]string, 0)
vendorInfoSlice = vendorInfo.([]string)
return fmt.Sprintf("%s = %s", vendorInfoSlice[0], vendorInfoSlice[2])
}