Skip to content

Commit 275f8be

Browse files
committed
v3 set added, bugfix, ui improved
1 parent be305df commit 275f8be

File tree

15 files changed

+561
-1381
lines changed

15 files changed

+561
-1381
lines changed

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
408408
TracerouteView tracerouteView;
409409
DNSLookupView dnsLookupView;
410410
RemoteDesktopView remoteDesktopView;
411-
SNMPHostView snmpHostView;
411+
SNMPView snmpView;
412412
WakeOnLANView wakeOnLANView;
413413
SubnetCalculatorHostView subnetCalculatorHostView;
414414
HTTPHeadersView httpHeadersView;
@@ -467,10 +467,10 @@ private void ChangeApplicationView(ApplicationViewManager.Name name)
467467
contentControlApplication.Content = remoteDesktopView;
468468
break;
469469
case ApplicationViewManager.Name.SNMP:
470-
if (snmpHostView == null)
471-
snmpHostView = new SNMPHostView();
470+
if (snmpView == null)
471+
snmpView = new SNMPView();
472472

473-
contentControlApplication.Content = snmpHostView;
473+
contentControlApplication.Content = snmpView;
474474
break;
475475
case ApplicationViewManager.Name.WakeOnLAN:
476476
if (wakeOnLANView == null)

Source/NETworkManager/Models/Network/SNMP.cs

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
using Lextm.SharpSnmpLib.Security;
44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics;
76
using System.Net;
87
using System.Threading.Tasks;
9-
using System.Windows;
108

119
namespace NETworkManager.Models.Network
1210
{
@@ -76,7 +74,7 @@ public void Getv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string commu
7674
});
7775
}
7876

79-
public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, SNMPOptions options, WalkMode walkMode)
77+
public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, WalkMode walkMode, SNMPOptions options)
8078
{
8179
Task.Run(() =>
8280
{
@@ -102,6 +100,27 @@ public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string comm
102100
});
103101
}
104102

103+
public void Setv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string communtiy, string oid, string data, SNMPOptions options)
104+
{
105+
Task.Run(() =>
106+
{
107+
try
108+
{
109+
Messenger.Set(version == SNMPVersion.v1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, options.Port), new OctetString(communtiy), new List<Variable> { new Variable(new ObjectIdentifier(oid), new OctetString(data)) }, options.Timeout);
110+
111+
OnComplete();
112+
}
113+
catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
114+
{
115+
OnTimeout();
116+
}
117+
catch (ErrorException)
118+
{
119+
OnError();
120+
}
121+
});
122+
}
123+
105124
public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, SNMPOptions options)
106125
{
107126
Task.Run(() =>
@@ -124,7 +143,9 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security,
124143
privacy = GetPrivacy();
125144

126145
GetRequestMessage request = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(username), new List<Variable> { new Variable(new ObjectIdentifier(oid)) }, privacy, Messenger.MaxMessageSize, report);
127-
Variable result = request.GetResponse(options.Timeout, ipEndpoint).Pdu().Variables[0];
146+
ISnmpMessage reply = request.GetResponse(options.Timeout, ipEndpoint);
147+
148+
Variable result = reply.Pdu().Variables[0];
128149

129150
OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
130151

@@ -141,7 +162,7 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security,
141162
});
142163
}
143164

144-
public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, SNMPOptions options, WalkMode walkMode)
165+
public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, WalkMode walkMode, SNMPOptions options)
145166
{
146167
Task.Run(() =>
147168
{
@@ -182,20 +203,36 @@ public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security
182203
});
183204
}
184205

185-
public void Setv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string communtiy, string oid, string data, SNMPOptions options)
206+
public void Setv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, string data, SNMPOptions options)
186207
{
187208
Task.Run(() =>
188209
{
189210
try
190211
{
191-
Messenger.Set(version == SNMPVersion.v1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, options.Port), new OctetString(communtiy), new List<Variable> { new Variable(new ObjectIdentifier(oid), new OctetString(data)) }, options.Timeout);
212+
IPEndPoint ipEndpoint = new IPEndPoint(ipAddress, options.Port);
213+
214+
// Discovery
215+
Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
216+
ReportMessage report = discovery.GetResponse(options.Timeout, ipEndpoint);
217+
218+
IPrivacyProvider privacy;
219+
220+
if (security == SNMPv3Security.authPriv)
221+
privacy = GetPrivacy(authProvider, auth, privProvider, priv);
222+
else if (security == SNMPv3Security.authNoPriv)
223+
privacy = GetPrivacy(authProvider, auth);
224+
else // noAuthNoPriv
225+
privacy = GetPrivacy();
226+
227+
SetRequestMessage request = new SetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(username), new List<Variable> { new Variable(new ObjectIdentifier(oid), new OctetString(data)) }, privacy, Messenger.MaxMessageSize, report);
228+
ISnmpMessage reply = request.GetResponse(options.Timeout, ipEndpoint);
192229

193230
OnComplete();
194231
}
195232
catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
196233
{
197234
OnTimeout();
198-
}
235+
}
199236
catch (ErrorException)
200237
{
201238
OnError();

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 40 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,170 +1532,114 @@ public bool SNMP_ResolveHostnamePreferIPv4
15321532
}
15331533
}
15341534

1535-
private ObservableCollection<string> _snmp_v1v2c_HostHistory = new ObservableCollection<string>();
1536-
public ObservableCollection<string> SNMP_v1v2c_HostHistory
1535+
private ObservableCollection<string> _snmp_HostHistory = new ObservableCollection<string>();
1536+
public ObservableCollection<string> SNMP_HostHistory
15371537
{
1538-
get { return _snmp_v1v2c_HostHistory; }
1538+
get { return _snmp_HostHistory; }
15391539
set
15401540
{
1541-
if (value == _snmp_v1v2c_HostHistory)
1541+
if (value == _snmp_HostHistory)
15421542
return;
15431543

1544-
_snmp_v1v2c_HostHistory = value;
1544+
_snmp_HostHistory = value;
15451545
SettingsChanged = true;
15461546
}
15471547
}
15481548

1549-
private ObservableCollection<string> _snmp_v1v2c_OIDHistory = new ObservableCollection<string>();
1550-
public ObservableCollection<string> SNMP_v1v2c_OIDHistory
1549+
private ObservableCollection<string> _snmp_OIDHistory = new ObservableCollection<string>();
1550+
public ObservableCollection<string> SNMP_OIDHistory
15511551
{
1552-
get { return _snmp_v1v2c_OIDHistory; }
1552+
get { return _snmp_OIDHistory; }
15531553
set
15541554
{
1555-
if (value == _snmp_v1v2c_OIDHistory)
1555+
if (value == _snmp_OIDHistory)
15561556
return;
15571557

1558-
_snmp_v1v2c_OIDHistory = value;
1558+
_snmp_OIDHistory = value;
15591559
SettingsChanged = true;
15601560
}
15611561
}
15621562

1563-
private SNMPMode _snmp_v1v2c_Mode = SNMPMode.Walk;
1564-
public SNMPMode SNMP_v1v2c_Mode
1563+
private SNMPMode _snmp_Mode = SNMPMode.Walk;
1564+
public SNMPMode SNMP_Mode
15651565
{
1566-
get { return _snmp_v1v2c_Mode; }
1566+
get { return _snmp_Mode; }
15671567
set
15681568
{
1569-
if (value == _snmp_v1v2c_Mode)
1569+
if (value == _snmp_Mode)
15701570
return;
15711571

1572-
_snmp_v1v2c_Mode = value;
1572+
_snmp_Mode = value;
15731573
SettingsChanged = true;
15741574
}
15751575
}
15761576

1577-
private SNMPVersion _snmp_v1v2c_Version = SNMPVersion.v2c;
1578-
public SNMPVersion SNMP_v1v2c_Version
1577+
private SNMPVersion _snmp_Version = SNMPVersion.v2c;
1578+
public SNMPVersion SNMP_Version
15791579
{
1580-
get { return _snmp_v1v2c_Version; }
1580+
get { return _snmp_Version; }
15811581
set
15821582
{
1583-
if (value == _snmp_v1v2c_Version)
1583+
if (value == _snmp_Version)
15841584
return;
15851585

1586-
_snmp_v1v2c_Version = value;
1586+
_snmp_Version = value;
15871587
SettingsChanged = true;
15881588
}
15891589
}
15901590

1591-
private bool _snmp_v1v2c_ExpandStatistics = true;
1592-
public bool SNMP_v1v2c_ExpandStatistics
1591+
private bool _snmp_ExpandStatistics = true;
1592+
public bool SNMP_ExpandStatistics
15931593
{
1594-
get { return _snmp_v1v2c_ExpandStatistics; }
1594+
get { return _snmp_ExpandStatistics; }
15951595
set
15961596
{
1597-
if (value == _snmp_v1v2c_ExpandStatistics)
1597+
if (value == _snmp_ExpandStatistics)
15981598
return;
15991599

1600-
_snmp_v1v2c_ExpandStatistics = value;
1600+
_snmp_ExpandStatistics = value;
16011601
SettingsChanged = true;
16021602
}
16031603
}
16041604

1605-
private ObservableCollection<string> _snmp_v3_HostHistory = new ObservableCollection<string>();
1606-
public ObservableCollection<string> SNMP_v3_HostHistory
1605+
private SNMPv3Security _snmp_Security = SNMPv3Security.authPriv;
1606+
public SNMPv3Security SNMP_Security
16071607
{
1608-
get { return _snmp_v3_HostHistory; }
1608+
get { return _snmp_Security; }
16091609
set
16101610
{
1611-
if (value == _snmp_v3_HostHistory)
1611+
if (value == _snmp_Security)
16121612
return;
16131613

1614-
_snmp_v3_HostHistory = value;
1614+
_snmp_Security = value;
16151615
SettingsChanged = true;
16161616
}
16171617
}
16181618

1619-
private ObservableCollection<string> _snmp_v3_OIDHistory = new ObservableCollection<string>();
1620-
public ObservableCollection<string> SNMP_v3_OIDHistory
1619+
private SNMPv3AuthenticationProvider _snmp_AuthenticationProvider = SNMPv3AuthenticationProvider.SHA1;
1620+
public SNMPv3AuthenticationProvider SNMP_AuthenticationProvider
16211621
{
1622-
get { return _snmp_v3_OIDHistory; }
1622+
get { return _snmp_AuthenticationProvider; }
16231623
set
16241624
{
1625-
if (value == _snmp_v3_OIDHistory)
1625+
if (value == _snmp_AuthenticationProvider)
16261626
return;
16271627

1628-
_snmp_v3_OIDHistory = value;
1628+
_snmp_AuthenticationProvider = value;
16291629
SettingsChanged = true;
16301630
}
16311631
}
16321632

1633-
private SNMPMode _snmp_v3_Mode = SNMPMode.Walk;
1634-
public SNMPMode SNMP_v3_Mode
1633+
private SNMPv3PrivacyProvider _snmp_PrivacyProvider = SNMPv3PrivacyProvider.AES;
1634+
public SNMPv3PrivacyProvider SNMP_PrivacyProvider
16351635
{
1636-
get { return _snmp_v3_Mode; }
1636+
get { return _snmp_PrivacyProvider; }
16371637
set
16381638
{
1639-
if (value == _snmp_v3_Mode)
1639+
if (value == _snmp_PrivacyProvider)
16401640
return;
16411641

1642-
_snmp_v3_Mode = value;
1643-
SettingsChanged = true;
1644-
}
1645-
}
1646-
1647-
private SNMPv3Security _snmp_v3_Security = SNMPv3Security.authPriv;
1648-
public SNMPv3Security SNMP_v3_Security
1649-
{
1650-
get { return _snmp_v3_Security; }
1651-
set
1652-
{
1653-
if (value == _snmp_v3_Security)
1654-
return;
1655-
1656-
_snmp_v3_Security = value;
1657-
SettingsChanged = true;
1658-
}
1659-
}
1660-
1661-
private SNMPv3AuthenticationProvider _snmp_v3_AuthenticationProvider = SNMPv3AuthenticationProvider.SHA1;
1662-
public SNMPv3AuthenticationProvider SNMP_v3_AuthenticationProvider
1663-
{
1664-
get { return _snmp_v3_AuthenticationProvider; }
1665-
set
1666-
{
1667-
if (value == _snmp_v3_AuthenticationProvider)
1668-
return;
1669-
1670-
_snmp_v3_AuthenticationProvider = value;
1671-
SettingsChanged = true;
1672-
}
1673-
}
1674-
1675-
private SNMPv3PrivacyProvider _snmp_v3_PrivacyProvider = SNMPv3PrivacyProvider.AES;
1676-
public SNMPv3PrivacyProvider SNMP_v3_PrivacyProvider
1677-
{
1678-
get { return _snmp_v3_PrivacyProvider; }
1679-
set
1680-
{
1681-
if (value == _snmp_v3_PrivacyProvider)
1682-
return;
1683-
1684-
_snmp_v3_PrivacyProvider = value;
1685-
SettingsChanged = true;
1686-
}
1687-
}
1688-
1689-
private bool _snmp_v3_ExpandStatistics = true;
1690-
public bool SNMP_v3_ExpandStatistics
1691-
{
1692-
get { return _snmp_v3_ExpandStatistics; }
1693-
set
1694-
{
1695-
if (value == _snmp_v3_ExpandStatistics)
1696-
return;
1697-
1698-
_snmp_v3_ExpandStatistics = value;
1642+
_snmp_PrivacyProvider = value;
16991643
SettingsChanged = true;
17001644
}
17011645
}

Source/NETworkManager/NETworkManager.csproj

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@
220220
<Compile Include="Models\Settings\RemoteDesktopSessionInfo.cs" />
221221
<Compile Include="Models\Update\UpdateAvailableArgs.cs" />
222222
<Compile Include="Models\Update\Updater.cs" />
223+
<Compile Include="Validators\PrivacyAESValidator.cs" />
223224
<Compile Include="Validators\OIDValidator.cs" />
224225
<Compile Include="Validators\Int32Validator.cs" />
225226
<Compile Include="Validators\MultipleIPAddressesValidator.cs" />
226227
<Compile Include="Validators\MultipleHostsValidator.cs" />
227228
<Compile Include="Validators\HttpAndHttpsUriValidator.cs" />
228229
<Compile Include="Validators\SubnetCalculatorSubnetValidator.cs" />
229230
<Compile Include="ViewModels\Applications\PingHostViewModel.cs" />
230-
<Compile Include="ViewModels\Applications\SNMPv3ViewModel.cs" />
231-
<Compile Include="ViewModels\Applications\SNMPv1v2cViewModel.cs" />
231+
<Compile Include="ViewModels\Applications\SNMPViewModel.cs" />
232232
<Compile Include="ViewModels\Applications\HTTPHeadersViewModel.cs" />
233233
<Compile Include="ViewModels\Applications\ARPTableViewModel.cs" />
234234
<Compile Include="ViewModels\Dialogs\CredentialsMasterPasswordViewModel.cs" />
@@ -275,14 +275,8 @@
275275
<Compile Include="Views\Applications\PingHostView.xaml.cs">
276276
<DependentUpon>PingHostView.xaml</DependentUpon>
277277
</Compile>
278-
<Compile Include="Views\Applications\SNMPv3View.xaml.cs">
279-
<DependentUpon>SNMPv3View.xaml</DependentUpon>
280-
</Compile>
281-
<Compile Include="Views\Applications\SNMPv1v2cView.xaml.cs">
282-
<DependentUpon>SNMPv1v2cView.xaml</DependentUpon>
283-
</Compile>
284-
<Compile Include="Views\Applications\SNMPHostView.xaml.cs">
285-
<DependentUpon>SNMPHostView.xaml</DependentUpon>
278+
<Compile Include="Views\Applications\SNMPView.xaml.cs">
279+
<DependentUpon>SNMPView.xaml</DependentUpon>
286280
</Compile>
287281
<Compile Include="Views\Applications\HTTPHeadersView.xaml.cs">
288282
<DependentUpon>HTTPHeadersView.xaml</DependentUpon>
@@ -462,15 +456,7 @@
462456
<Generator>MSBuild:Compile</Generator>
463457
<SubType>Designer</SubType>
464458
</Page>
465-
<Page Include="Views\Applications\SNMPv3View.xaml">
466-
<Generator>MSBuild:Compile</Generator>
467-
<SubType>Designer</SubType>
468-
</Page>
469-
<Page Include="Views\Applications\SNMPv1v2cView.xaml">
470-
<Generator>MSBuild:Compile</Generator>
471-
<SubType>Designer</SubType>
472-
</Page>
473-
<Page Include="Views\Applications\SNMPHostView.xaml">
459+
<Page Include="Views\Applications\SNMPView.xaml">
474460
<Generator>MSBuild:Compile</Generator>
475461
<SubType>Designer</SubType>
476462
</Page>

0 commit comments

Comments
 (0)