Skip to content

Commit 055ee81

Browse files
committed
Updated dependencies.
1 parent 0fe1bbf commit 055ee81

File tree

6 files changed

+131
-27
lines changed

6 files changed

+131
-27
lines changed

.vscode/launch.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": ".NET Core Launch (console)",
8+
"name": "snmpd Launch (console)",
99
"type": "coreclr",
1010
"request": "launch",
1111
"preLaunchTask": "build",
@@ -16,10 +16,33 @@
1616
"stopAtEntry": false,
1717
"justMyCode": false
1818
},
19+
{
20+
"name": "snmpget Launch (console)",
21+
"type": "coreclr",
22+
"request": "launch",
23+
"preLaunchTask": "build",
24+
"program": "${workspaceFolder}/Samples/CSharpCore/snmpget/bin/Debug/net8.0/snmpget.dll",
25+
"args": [
26+
"-v=3",
27+
"-u=usr-md5-des",
28+
"-a=MD5",
29+
"-A=authkey1",
30+
"-x=DES",
31+
"-X=privkey1",
32+
"-d",
33+
"localhost:1610",
34+
"1.3.6.1.2.1.1.1.0",
35+
"1.3.6.1.2.1.1.2.0"
36+
],
37+
"cwd": "${workspaceFolder}/Samples/CSharpCore/snmpget",
38+
"console": "internalConsole",
39+
"stopAtEntry": false,
40+
"justMyCode": false
41+
},
1942
{
2043
"name": ".NET Core Attach",
2144
"type": "coreclr",
2245
"request": "attach"
2346
}
2447
]
25-
}
48+
}

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "process",
88
"args": [
99
"build",
10-
"${workspaceFolder}/Samples/CSharpCore/snmpd/snmpd.csproj",
10+
"${workspaceFolder}/SharpSnmpLib.Samples.sln",
1111
"/property:GenerateFullPaths=true",
1212
"/consoleloggerparameters:NoSummary"
1313
],
@@ -38,4 +38,4 @@
3838
"problemMatcher": "$msCompile"
3939
}
4040
]
41-
}
41+
}

Samples.Engine/Samples.Engine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.5" />
1515
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
16-
<PackageReference Include="System.Memory" Version="4.5.5" />
16+
<PackageReference Include="System.Memory" Version="4.6.3" />
1717
</ItemGroup>
1818
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
1919
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />

Samples/CSharpCore/snmpget/Program.cs

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void Main(string[] args)
6060
})
6161
.Add("a:", "Authentication method (MD5, SHA, SHA256, SHA384, or SHA512)", delegate (string v) { authentication = v; })
6262
.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; })
6464
.Add("X:", "Privacy passphrase", delegate (string v) { privPhrase = v; })
6565
.Add("u:", "Security name", delegate (string v) { user = v; })
6666
.Add("C:", "Context name", delegate (string v) { contextName = v; })
@@ -126,12 +126,26 @@ public static void Main(string[] args)
126126
Console.WriteLine(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyVersionAttribute>().Version);
127127
return;
128128
}
129-
129+
130130
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);
132146
if (!parsed)
133147
{
134-
var addresses = Dns.GetHostAddressesAsync(extra[0]);
148+
var addresses = Dns.GetHostAddressesAsync(hostNameOrAddress);
135149
addresses.Wait();
136150
foreach (IPAddress address in
137151
addresses.Result.Where(address => address.AddressFamily == AddressFamily.InterNetwork))
@@ -142,7 +156,7 @@ public static void Main(string[] args)
142156

143157
if (ip == null)
144158
{
145-
Console.WriteLine("invalid host or wrong IP address found: " + extra[0]);
159+
Console.WriteLine("invalid host or wrong IP address found: " + hostNameOrAddress);
146160
return;
147161
}
148162
}
@@ -156,7 +170,7 @@ public static void Main(string[] args)
156170
vList.Add(test);
157171
}
158172

159-
IPEndPoint receiver = new IPEndPoint(ip, 161);
173+
IPEndPoint receiver = new IPEndPoint(ip, port);
160174
if (version != VersionCode.V3)
161175
{
162176
foreach (
@@ -182,15 +196,7 @@ Variable variable in
182196
IPrivacyProvider priv;
183197
if ((level & Levels.Privacy) == Levels.Privacy)
184198
{
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);
194200
}
195201
else
196202
{
@@ -253,6 +259,75 @@ private static void ShowHelp(OptionSet optionSet)
253259
optionSet.WriteOptionDescriptions(Console.Out);
254260
}
255261

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+
256331
private static IAuthenticationProvider GetAuthenticationProviderByName(string authentication, string phrase)
257332
{
258333
if (authentication.ToUpperInvariant() == "MD5")

Tests/CSharpCore/Tests.NetStandard.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<!-- Detect SDK version -->
1111
<ParsedSdkVersion>$([System.Text.RegularExpressions.Regex]::Replace($(NETCoreSdkVersion), '-.*',
1212
''))</ParsedSdkVersion>
13-
<IsNet80Supported Condition="'$(ParsedSdkVersion)' >= '8.0'">true</IsNet80Supported>
14-
<IsNet90Supported Condition="'$(ParsedSdkVersion)' >= '9.0'">true</IsNet90Supported>
13+
<IsNet80Supported Condition="'$(ParsedSdkVersion)' &gt;= '8.0'">true</IsNet80Supported>
14+
<IsNet90Supported Condition="'$(ParsedSdkVersion)' &gt;= '9.0'">true</IsNet90Supported>
1515
<!-- Only support .NET 6/8/9 and .NET Framework 4.7.1 right now. -->
1616
<TargetFrameworks Condition="'$(IsNet80Supported)' == 'true' ">net8.0</TargetFrameworks>
1717
<TargetFrameworks Condition="'$(IsNet90Supported)' == 'true' ">$(TargetFrameworks);net9.0</TargetFrameworks>
@@ -36,16 +36,16 @@
3636
<None Include="sharpsnmplib.tests.snk" />
3737
</ItemGroup>
3838
<ItemGroup>
39-
<PackageReference Include="AltCover" Version="8.9.3" />
39+
<PackageReference Include="AltCover" Version="9.0.1" />
4040
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.5" />
41-
<PackageReference Include="NSubstitute" Version="5.1.0" />
41+
<PackageReference Include="NSubstitute" Version="5.3.0" />
4242
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
43-
<PackageReference Include="xunit" Version="2.9.2" />
44-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
43+
<PackageReference Include="xunit" Version="2.9.3" />
44+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
4545
<PrivateAssets>all</PrivateAssets>
4646
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4747
</PackageReference>
48-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
48+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
4949
</ItemGroup>
5050
<ItemGroup Condition="'$(TargetFramework)'!='net471'">
5151
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "9.0.100",
4+
"rollForward": "latestMinor"
5+
}
6+
}

0 commit comments

Comments
 (0)