-
Notifications
You must be signed in to change notification settings - Fork 27
/
descrstat.go
149 lines (125 loc) · 3.32 KB
/
descrstat.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package sw
import (
"log"
"strconv"
"strings"
"time"
"github.com/ulricqin/gosnmp"
)
func SysDescr(ip, community string, retry int, timeout int) (string, error) {
defer func() {
if r := recover(); r != nil {
log.Println(ip+" Recovered in sysDescr", r)
}
}()
oid := "1.3.6.1.2.1.1.1.0"
method := "get"
var snmpPDUs []gosnmp.SnmpPDU
var err error
for i := 0; i < retry; i++ {
snmpPDUs, err = RunSnmp(ip, community, oid, method, timeout)
if len(snmpPDUs) > 0 {
break
}
time.Sleep(100 * time.Millisecond)
}
if err == nil {
for _, pdu := range snmpPDUs {
return pdu.Value.(string), err
}
}
return "", err
}
func SysVendor(ip, community string, retry int, timeout int) (string, error) {
sysDescr, err := SysDescr(ip, community, retry, timeout)
sysDescrLower := strings.ToLower(sysDescr)
if strings.Contains(sysDescrLower, "cisco nx-os") {
return "Cisco_NX", err
}
if strings.Contains(sysDescr, "Cisco Internetwork Operating System Software") {
return "Cisco_old", err
}
if strings.Contains(sysDescrLower, "cisco ios") {
if strings.Contains(sysDescr, "IOS-XE Software") {
return "Cisco_IOS_XE", err
} else if strings.Contains(sysDescr, "Cisco IOS XR") {
return "Cisco_IOS_XR", err
} else {
return "Cisco", err
}
}
if strings.Contains(sysDescrLower, "cisco controller") {
return "Cisco_Controller", err
}
if strings.Contains(sysDescrLower, "cisco adaptive security appliance") {
version_number, err := strconv.ParseFloat(getVersionNumber(sysDescr), 32)
if err == nil && version_number < 9.2 {
return "Cisco_ASA_OLD", err
}
return "Cisco_ASA", err
}
if strings.Contains(sysDescrLower, "h3c") {
if strings.Contains(sysDescr, "Software Version 5") {
return "H3C_V5", err
}
if strings.Contains(sysDescr, "Software Version 7") {
return "H3C_V7", err
}
if strings.Contains(sysDescr, "Version S9500") {
return "H3C_S9500", err
}
if strings.Contains(sysDescr, "Version 3.10") {
return "H3c_V3.10", err
}
return "H3C", err
}
if strings.Contains(sysDescrLower, "huawei") {
if strings.Contains(sysDescr, "MultiserviceEngine 60") {
return "Huawei_ME60", err
}
if strings.Contains(sysDescr, "Version 5.70") {
return "Huawei_V5.70", err
}
if strings.Contains(sysDescr, "Version 5.130") {
return "Huawei_V5.130", err
}
if strings.Contains(sysDescr, "Version 3.10") {
return "Huawei_V3.10", err
}
return "Huawei", err
}
if strings.Contains(sysDescrLower, "ruijie") {
return "Ruijie", err
}
if strings.Contains(sysDescrLower, "juniper networks") {
return "Juniper", err
}
if strings.Contains(sysDescrLower, "dell networking") {
return "Dell", err
}
if strings.Contains(sysDescrLower, "linux") {
return "Linux", err
}
if strings.Contains(sysDescrLower, "thunder series") {
return "A10", err
}
if strings.Contains(sysDescrLower, "arubaos") {
return "Aruba", err
}
if strings.Contains(sysDescrLower, "hillstone") {
return "Hillstone", err
}
return "", err
}
func getVersionNumber(sysdescr string) string {
version_number := ""
s := strings.Fields(sysdescr)
for index, value := range s {
if strings.ToLower(value) == "version" {
version_number = s[index+1]
}
}
version_number = strings.Replace(version_number, "(", "", -1)
version_number = strings.Replace(version_number, ")", "", -1)
return version_number
}