@@ -49,10 +49,10 @@ def run_host(ip)
49
49
"RADIUS Server" , "RADIUS Port" , "RADIUS Key"
50
50
]
51
51
52
- output_data = { }
53
52
output_data = { "Host IP" => ip }
54
53
55
- if snmp . get_value ( 'sysDescr.0' ) . to_s =~ /SBG6580/
54
+ sys_descr = snmp . get_value ( 'sysDescr.0' )
55
+ if is_valid_snmp_value ( sys_descr ) and sys_descr . to_s =~ /SBG6580/
56
56
# print connected status after the first query so if there are
57
57
# any timeout or connectivity errors; the code would already
58
58
# have jumped to error handling where the error status is
@@ -63,81 +63,114 @@ def run_host(ip)
63
63
# using the CableHome cabhPsDevMib MIB module which defines the
64
64
# basic management objects for the Portal Services (PS) logical element
65
65
# of a CableHome compliant Residential Gateway device
66
- device_ui_selection = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.3.0' ) . to_i
67
- if device_ui_selection == 1
66
+ device_ui_selection = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.3.0' )
67
+ if is_valid_snmp_value ( device_ui_selection ) and device_ui_selection . to_i == 1
68
68
# manufacturerLocal(1) - indicates Portal Services is using the vendor
69
69
# web user interface shipped with the device
70
- device_ui_username = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.1.0' ) . to_s
71
- output_data [ "Username" ] = device_ui_username . strip
70
+ device_ui_username = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.1.0' )
71
+ if is_valid_snmp_value ( device_ui_username )
72
+ output_data [ "Username" ] = device_ui_username . to_s
73
+ end
72
74
73
- device_ui_password = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.2.0' ) . to_s
74
- output_data [ "Password" ] = device_ui_password . strip
75
+ device_ui_password = snmp . get_value ( '1.3.6.1.4.1.4491.2.4.1.1.6.1.2.0' )
76
+ if is_valid_snmp_value ( device_ui_password )
77
+ output_data [ "Password" ] = device_ui_password . to_s
78
+ end
75
79
end
76
80
77
- primary_wifi_state = snmp . get_value ( '1.3.6.1.2.1.2.2.1.8.32' ) . to_i
78
- if primary_wifi_state != 1
79
- # primary Wifi interface is not up
81
+ wifi_ifindex = get_primary_wifi_ifindex ( snmp )
82
+ if wifi_ifindex < 1
80
83
print_status ( "Primary WiFi is disabled on the device" )
81
84
end
82
85
83
- ssid = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.1.14.1.3.32' ) . to_s
84
- output_data [ "SSID" ] = ssid . strip
86
+ ssid = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.1.14.1.3.#{ wifi_ifindex } " )
87
+ if is_valid_snmp_value ( ssid )
88
+ output_data [ "SSID" ] = ssid . to_s
89
+ end
85
90
86
- wireless_band = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.1.18.0' ) . to_i
87
- output_data [ "802.11 Band" ] = get_wireless_band_name ( wireless_band )
91
+ wireless_band = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.1.18.0' )
92
+ if is_valid_snmp_value ( wireless_band )
93
+ output_data [ "802.11 Band" ] = get_wireless_band_name ( wireless_band . to_i )
94
+ end
88
95
89
- network_auth_mode = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.1.14.1.5.32' ) . to_i
90
- network_auth_mode_name = get_network_auth_mode_name ( network_auth_mode )
91
- output_data [ "Network Authentication Mode" ] = network_auth_mode_name
96
+ network_auth_mode = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.1.14.1.5.#{ wifi_ifindex } " )
97
+ if is_valid_snmp_value ( network_auth_mode )
98
+ network_auth_mode = network_auth_mode . to_i
99
+ network_auth_mode_name = get_network_auth_mode_name ( network_auth_mode )
100
+ output_data [ "Network Authentication Mode" ] = network_auth_mode_name
101
+ end
92
102
93
103
case network_auth_mode
94
104
when 1 , 6
95
105
# WEP, WEP 802.1x Authentication
96
- wep_passphrase = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.3.32' ) . to_s
97
- output_data [ "WEP Passphrase" ] = wep_passphrase . strip
106
+ wep_passphrase = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.3.#{ wifi_ifindex } " )
107
+ if is_valid_snmp_value ( wep_passphrase )
108
+ output_data [ "WEP Passphrase" ] = wep_passphrase . to_s
109
+ end
98
110
99
- wep_encryption = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.2.32' ) . to_i
100
- wep_encryption_name = "unknown"
101
- wep_key1 = wep_key2 = wep_key3 = wep_key4 = ""
111
+ wep_encryption = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.2.#{ wifi_ifindex } " )
112
+ if is_valid_snmp_value ( wep_encryption )
113
+ wep_encryption = wep_encryption . to_i
114
+ else
115
+ wep_encryption = -1
116
+ end
117
+
118
+ wep_encryption_name = "Unknown"
119
+ wep_key1 = wep_key2 = wep_key3 = wep_key4 = nil
102
120
# get appropriate WEP keys based on wep_encryption setting
103
121
if wep_encryption == 1
104
122
wep_encryption_name = "64-bit"
105
- wep_key1 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.32.1' )
106
- wep_key2 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.32.2' )
107
- wep_key3 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.32.3' )
108
- wep_key4 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.32.4' )
123
+ wep_key1 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.#{ wifi_ifindex } .1" )
124
+ wep_key2 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.#{ wifi_ifindex } .2" )
125
+ wep_key3 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.#{ wifi_ifindex } .3" )
126
+ wep_key4 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.2.1.2.#{ wifi_ifindex } .4" )
109
127
elsif wep_encryption == 2
110
128
wep_encryption_name = "128-bit"
111
- wep_key1 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.32.1' )
112
- wep_key2 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.32.2' )
113
- wep_key3 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.32.3' )
114
- wep_key4 = snmp . get_value ( ' 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.32.4' )
129
+ wep_key1 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.#{ wifi_ifindex } .1" )
130
+ wep_key2 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.#{ wifi_ifindex } .2" )
131
+ wep_key3 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.#{ wifi_ifindex } .3" )
132
+ wep_key4 = snmp . get_value ( " 1.3.6.1.4.1.4413.2.2.2.1.5.4.2.3.1.2.#{ wifi_ifindex } .4" )
115
133
end
134
+
116
135
output_data [ "WEP Encryption" ] = wep_encryption_name
117
- output_data [ "WEP Key 1" ] = wep_key1 . unpack ( 'H*' ) [ 0 ]
118
- output_data [ "WEP Key 2" ] = wep_key2 . unpack ( 'H*' ) [ 0 ]
119
- output_data [ "WEP Key 3" ] = wep_key3 . unpack ( 'H*' ) [ 0 ]
120
- output_data [ "WEP Key 4" ] = wep_key4 . unpack ( 'H*' ) [ 0 ]
136
+ if is_valid_snmp_value ( wep_key1 )
137
+ output_data [ "WEP Key 1" ] = wep_key1 . unpack ( 'H*' ) [ 0 ]
138
+ end
139
+ if is_valid_snmp_value ( wep_key2 )
140
+ output_data [ "WEP Key 2" ] = wep_key2 . unpack ( 'H*' ) [ 0 ]
141
+ end
142
+ if is_valid_snmp_value ( wep_key3 )
143
+ output_data [ "WEP Key 3" ] = wep_key3 . unpack ( 'H*' ) [ 0 ]
144
+ end
145
+ if is_valid_snmp_value ( wep_key4 )
146
+ output_data [ "WEP Key 4" ] = wep_key4 . unpack ( 'H*' ) [ 0 ]
147
+ end
121
148
122
149
# get current network key
123
- current_key = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.1.32' ) . to_s
124
- output_data [ "Current Network Key" ] = current_key
150
+ current_key = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.1.1.1.#{ wifi_ifindex } " )
151
+ if is_valid_snmp_value ( current_key )
152
+ output_data [ "Current Network Key" ] = current_key . to_s
153
+ end
125
154
126
155
if network_auth_mode == 6
127
- get_radius_info ( snmp , output_data )
156
+ get_radius_info ( snmp , wifi_ifindex , output_data )
128
157
end
129
158
130
159
when 2 , 3 , 4 , 5 , 7 , 8
131
160
# process all flavors of WPA
132
- wpa_encryption = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.4.1.1.32' ) . to_i
133
- output_data [ "WPA Encryption" ] = get_wpa_encryption_name ( wpa_encryption )
161
+ wpa_encryption = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.4.1.1.#{ wifi_ifindex } " )
162
+ if is_valid_snmp_value ( wpa_encryption )
163
+ output_data [ "WPA Encryption" ] = get_wpa_encryption_name ( wpa_encryption . to_i )
164
+ end
134
165
135
- wpa_psk = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.4.1.2.32' ) . to_s
136
- output_data [ "WPA Pre-Shared Key (PSK)" ] = wpa_psk . strip
166
+ wpa_psk = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.4.1.2.#{ wifi_ifindex } " )
167
+ if is_valid_snmp_value ( wpa_psk )
168
+ output_data [ "WPA Pre-Shared Key (PSK)" ] = wpa_psk . to_s
169
+ end
137
170
138
171
case network_auth_mode
139
172
when 4 , 5 , 8
140
- get_radius_info ( snmp , output_data )
173
+ get_radius_info ( snmp , wifi_ifindex , output_data )
141
174
end
142
175
end
143
176
@@ -193,6 +226,27 @@ def run_host(ip)
193
226
end
194
227
end
195
228
229
+ def get_primary_wifi_ifindex ( snmp )
230
+ # The ifTable contains interface entries where each row represents
231
+ # management information for a particular interface. Locate the first
232
+ # interface where ifType is 71 (ieee80211) and ifAdminStatus is 1 (up).
233
+ wifi_ifindex = 0
234
+ ifTable_columns = [ "ifIndex" , "ifDescr" , "ifType" , "ifAdminStatus" ]
235
+ snmp . walk ( ifTable_columns ) do |ifIndex , ifDescr , ifType , ifAdminStatus |
236
+ if ( wifi_ifindex < 1 and ifType . value == 71 and ifAdminStatus . value == 1 )
237
+ wifi_ifindex = ifIndex . value . to_i
238
+ end
239
+ end
240
+ wifi_ifindex
241
+ end
242
+
243
+ def is_valid_snmp_value ( value )
244
+ if value . nil? or value . to_s =~ /Null/ or value . to_s =~ /^noSuch/
245
+ return false
246
+ end
247
+ return true
248
+ end
249
+
196
250
def get_network_auth_mode_name ( network_auth_mode )
197
251
case network_auth_mode
198
252
when 0
@@ -240,15 +294,21 @@ def get_wpa_encryption_name(wpa_encryption)
240
294
end
241
295
end
242
296
243
- def get_radius_info ( snmp , output_data )
244
- radius_server = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.2.32' )
245
- output_data [ "RADIUS Server" ] = radius_server . unpack ( "C4" ) . join ( "." )
297
+ def get_radius_info ( snmp , wifi_ifindex , output_data )
298
+ radius_server = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.2.#{ wifi_ifindex } " )
299
+ if is_valid_snmp_value ( radius_server )
300
+ output_data [ "RADIUS Server" ] = radius_server . unpack ( "C4" ) . join ( "." )
301
+ end
246
302
247
- radius_port = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.3.32' ) . to_s
248
- output_data [ "RADIUS Port" ] = radius_port . strip
303
+ radius_port = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.3.#{ wifi_ifindex } " )
304
+ if is_valid_snmp_value ( radius_port )
305
+ output_data [ "RADIUS Port" ] = radius_port . to_s . strip
306
+ end
249
307
250
- radius_key = snmp . get_value ( '1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.4.32' ) . to_s
251
- output_data [ "RADIUS Key" ] = radius_key . strip
308
+ radius_key = snmp . get_value ( "1.3.6.1.4.1.4413.2.2.2.1.5.4.2.5.1.4.#{ wifi_ifindex } " )
309
+ if is_valid_snmp_value ( radius_key )
310
+ output_data [ "RADIUS Key" ] = radius_key . to_s
311
+ end
252
312
end
253
313
254
314
end
0 commit comments