@@ -60,7 +60,7 @@ public static void Main(string[] args)
60
60
} )
61
61
. Add ( "a:" , "Authentication method (MD5, SHA, SHA256, SHA384, or SHA512)" , delegate ( string v ) { authentication = v ; } )
62
62
. Add ( "A:" , "Authentication passphrase" , delegate ( string v ) { authPhrase = v ; } )
63
- . Add ( "x:" , "Privacy method" , delegate ( string v ) { privacy = v ; } )
63
+ . Add ( "x:" , "Privacy method (DES, 3DES, AES, AES192, or AES256) " , delegate ( string v ) { privacy = v ; } )
64
64
. Add ( "X:" , "Privacy passphrase" , delegate ( string v ) { privPhrase = v ; } )
65
65
. Add ( "u:" , "Security name" , delegate ( string v ) { user = v ; } )
66
66
. Add ( "C:" , "Context name" , delegate ( string v ) { contextName = v ; } )
@@ -126,12 +126,26 @@ public static void Main(string[] args)
126
126
Console . WriteLine ( Assembly . GetEntryAssembly ( ) . GetCustomAttribute < AssemblyVersionAttribute > ( ) . Version ) ;
127
127
return ;
128
128
}
129
-
129
+
130
130
IPAddress ip ;
131
- bool parsed = IPAddress . TryParse ( extra [ 0 ] , out ip ) ;
131
+ int port = 161 ; // Default SNMP port
132
+ string hostNameOrAddress = extra [ 0 ] ;
133
+
134
+ // Handle host:port format
135
+ if ( hostNameOrAddress . Contains ( ':' ) )
136
+ {
137
+ string [ ] parts = hostNameOrAddress . Split ( ':' ) ;
138
+ if ( parts . Length == 2 && int . TryParse ( parts [ 1 ] , out int parsedPort ) )
139
+ {
140
+ hostNameOrAddress = parts [ 0 ] ;
141
+ port = parsedPort ;
142
+ }
143
+ }
144
+
145
+ bool parsed = IPAddress . TryParse ( hostNameOrAddress , out ip ) ;
132
146
if ( ! parsed )
133
147
{
134
- var addresses = Dns . GetHostAddressesAsync ( extra [ 0 ] ) ;
148
+ var addresses = Dns . GetHostAddressesAsync ( hostNameOrAddress ) ;
135
149
addresses . Wait ( ) ;
136
150
foreach ( IPAddress address in
137
151
addresses . Result . Where ( address => address . AddressFamily == AddressFamily . InterNetwork ) )
@@ -142,7 +156,7 @@ public static void Main(string[] args)
142
156
143
157
if ( ip == null )
144
158
{
145
- Console . WriteLine ( "invalid host or wrong IP address found: " + extra [ 0 ] ) ;
159
+ Console . WriteLine ( "invalid host or wrong IP address found: " + hostNameOrAddress ) ;
146
160
return ;
147
161
}
148
162
}
@@ -156,7 +170,7 @@ public static void Main(string[] args)
156
170
vList . Add ( test ) ;
157
171
}
158
172
159
- IPEndPoint receiver = new IPEndPoint ( ip , 161 ) ;
173
+ IPEndPoint receiver = new IPEndPoint ( ip , port ) ;
160
174
if ( version != VersionCode . V3 )
161
175
{
162
176
foreach (
@@ -182,15 +196,7 @@ Variable variable in
182
196
IPrivacyProvider priv ;
183
197
if ( ( level & Levels . Privacy ) == Levels . Privacy )
184
198
{
185
- if ( DESPrivacyProvider . IsSupported )
186
- {
187
- priv = new DESPrivacyProvider ( new OctetString ( privPhrase ) , auth ) ;
188
- }
189
- else
190
- {
191
- Console . WriteLine ( "DES (ECB) is not supported by .NET Core." ) ;
192
- return ;
193
- }
199
+ priv = GetPrivacyProviderByName ( privacy , privPhrase , auth ) ;
194
200
}
195
201
else
196
202
{
@@ -253,6 +259,75 @@ private static void ShowHelp(OptionSet optionSet)
253
259
optionSet . WriteOptionDescriptions ( Console . Out ) ;
254
260
}
255
261
262
+ private static IPrivacyProvider GetPrivacyProviderByName ( string privacy , string phrase , IAuthenticationProvider auth )
263
+ {
264
+ if ( string . IsNullOrEmpty ( privacy ) )
265
+ {
266
+ return new DefaultPrivacyProvider ( auth ) ;
267
+ }
268
+
269
+ switch ( privacy . ToUpperInvariant ( ) )
270
+ {
271
+ case "DES" :
272
+ if ( DESPrivacyProvider . IsSupported )
273
+ {
274
+ return new DESPrivacyProvider ( new OctetString ( phrase ) , auth ) ;
275
+ }
276
+
277
+ throw new ArgumentException ( "DES privacy is not supported in this system" ) ;
278
+
279
+ case "3DES" :
280
+ return new TripleDESPrivacyProvider ( new OctetString ( phrase ) , auth ) ;
281
+
282
+ case "AES" :
283
+ if ( AESPrivacyProvider . IsSupported )
284
+ {
285
+ return new AESPrivacyProvider ( new OctetString ( phrase ) , auth ) ; ;
286
+ }
287
+
288
+ throw new ArgumentException ( "AES privacy is not supported in this system" ) ;
289
+
290
+ case "AES192" :
291
+ if ( AESPrivacyProvider . IsSupported )
292
+ {
293
+ return new AES192PrivacyProvider ( new OctetString ( phrase ) , auth ) ;
294
+ }
295
+
296
+ throw new ArgumentException ( "AES192 privacy is not supported in this system" ) ;
297
+
298
+ case "AES256" :
299
+ if ( AESPrivacyProvider . IsSupported )
300
+ {
301
+ return new AES256PrivacyProvider ( new OctetString ( phrase ) , auth ) ;
302
+ }
303
+
304
+ throw new ArgumentException ( "AES256 privacy is not supported in this system" ) ;
305
+
306
+ default :
307
+ throw new ArgumentException ( "unknown privacy name: " + privacy ) ;
308
+ }
309
+ }
310
+
311
+ private static Type GetType ( string typeName )
312
+ {
313
+ var type = Type . GetType ( typeName ) ;
314
+ if ( type != null )
315
+ {
316
+ return type ;
317
+ }
318
+
319
+ foreach ( var assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
320
+ {
321
+ type = assembly . GetType ( typeName ) ;
322
+ if ( type != null )
323
+ {
324
+ return type ;
325
+ }
326
+ }
327
+
328
+ return null ;
329
+ }
330
+
256
331
private static IAuthenticationProvider GetAuthenticationProviderByName ( string authentication , string phrase )
257
332
{
258
333
if ( authentication . ToUpperInvariant ( ) == "MD5" )
0 commit comments