Skip to content

Commit

Permalink
Merge pull request #76 from BornToBeRoot/snmp-set
Browse files Browse the repository at this point in the history
SNMP improved
  • Loading branch information
BornToBeRoot authored Feb 24, 2018
2 parents 208970d + 275f8be commit 07ac7e4
Show file tree
Hide file tree
Showing 41 changed files with 999 additions and 1,407 deletions.
2 changes: 1 addition & 1 deletion Source/NETworkManager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class App : Application
// Single instance unique identifier
private const string Guid = "6A3F34B2-161F-4F70-A8BC-A19C40F79CFB";
Mutex _mutex;

private bool _singleInstanceClose = false;

public App()
Expand Down
3 changes: 3 additions & 0 deletions Source/NETworkManager/Helpers/RegexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ public static class RegexHelper

// Test for http|https uris
public const string httpAndHttpsUriRegex = @"^http(s)?:\/\/([\w-]+.)+[\w-]+(\/[\w- ./?%&=])?$";

// OID (SNMP)
public const string OIDRegex = @"^([1-9][0-9]{0,3}|0)(\.([1-9][0-9]{0,3}|0)){5,13}$";
}
}
8 changes: 4 additions & 4 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
TracerouteView tracerouteView;
DNSLookupView dnsLookupView;
RemoteDesktopView remoteDesktopView;
SNMPHostView snmpHostView;
SNMPView snmpView;
WakeOnLANView wakeOnLANView;
SubnetCalculatorHostView subnetCalculatorHostView;
HTTPHeadersView httpHeadersView;
Expand Down Expand Up @@ -467,10 +467,10 @@ private void ChangeApplicationView(ApplicationViewManager.Name name)
contentControlApplication.Content = remoteDesktopView;
break;
case ApplicationViewManager.Name.SNMP:
if (snmpHostView == null)
snmpHostView = new SNMPHostView();
if (snmpView == null)
snmpView = new SNMPView();

contentControlApplication.Content = snmpHostView;
contentControlApplication.Content = snmpView;
break;
case ApplicationViewManager.Name.WakeOnLAN:
if (wakeOnLANView == null)
Expand Down
70 changes: 66 additions & 4 deletions Source/NETworkManager/Models/Network/SNMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Getv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string commu
});
}

public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, SNMPOptions options, WalkMode walkMode)
public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, WalkMode walkMode, SNMPOptions options)
{
Task.Run(() =>
{
Expand All @@ -100,6 +100,27 @@ public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string comm
});
}

public void Setv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string communtiy, string oid, string data, SNMPOptions options)
{
Task.Run(() =>
{
try
{
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);
OnComplete();
}
catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
{
OnTimeout();
}
catch (ErrorException)
{
OnError();
}
});
}

public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, SNMPOptions options)
{
Task.Run(() =>
Expand All @@ -122,7 +143,9 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security,
privacy = GetPrivacy();
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);
Variable result = request.GetResponse(options.Timeout, ipEndpoint).Pdu().Variables[0];
ISnmpMessage reply = request.GetResponse(options.Timeout, ipEndpoint);
Variable result = reply.Pdu().Variables[0];
OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
Expand All @@ -139,7 +162,7 @@ public void Getv3Async(IPAddress ipAddress, string oid, SNMPv3Security security,
});
}

public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, SNMPOptions options, WalkMode walkMode)
public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, WalkMode walkMode, SNMPOptions options)
{
Task.Run(() =>
{
Expand Down Expand Up @@ -180,6 +203,43 @@ public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security
});
}

public void Setv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, string data, SNMPOptions options)
{
Task.Run(() =>
{
try
{
IPEndPoint ipEndpoint = new IPEndPoint(ipAddress, options.Port);
// Discovery
Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
ReportMessage report = discovery.GetResponse(options.Timeout, ipEndpoint);
IPrivacyProvider privacy;
if (security == SNMPv3Security.authPriv)
privacy = GetPrivacy(authProvider, auth, privProvider, priv);
else if (security == SNMPv3Security.authNoPriv)
privacy = GetPrivacy(authProvider, auth);
else // noAuthNoPriv
privacy = GetPrivacy();
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);
ISnmpMessage reply = request.GetResponse(options.Timeout, ipEndpoint);
OnComplete();
}
catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
{
OnTimeout();
}
catch (ErrorException)
{
OnError();
}
});
}

// noAuthNoPriv
private IPrivacyProvider GetPrivacy()
{
Expand Down Expand Up @@ -224,12 +284,14 @@ public enum SNMPVersion
v3
}

// Trap and Inform not implemented
public enum SNMPMode
{
Get,
Walk,
Set,
Trap
Trap,
Inform
}

public enum SNMPv3Security
Expand Down
136 changes: 40 additions & 96 deletions Source/NETworkManager/Models/Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,170 +1532,114 @@ public bool SNMP_ResolveHostnamePreferIPv4
}
}

private ObservableCollection<string> _snmp_v1v2c_HostHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_v1v2c_HostHistory
private ObservableCollection<string> _snmp_HostHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_HostHistory
{
get { return _snmp_v1v2c_HostHistory; }
get { return _snmp_HostHistory; }
set
{
if (value == _snmp_v1v2c_HostHistory)
if (value == _snmp_HostHistory)
return;

_snmp_v1v2c_HostHistory = value;
_snmp_HostHistory = value;
SettingsChanged = true;
}
}

private ObservableCollection<string> _snmp_v1v2c_OIDHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_v1v2c_OIDHistory
private ObservableCollection<string> _snmp_OIDHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_OIDHistory
{
get { return _snmp_v1v2c_OIDHistory; }
get { return _snmp_OIDHistory; }
set
{
if (value == _snmp_v1v2c_OIDHistory)
if (value == _snmp_OIDHistory)
return;

_snmp_v1v2c_OIDHistory = value;
_snmp_OIDHistory = value;
SettingsChanged = true;
}
}

private SNMPMode _snmp_v1v2c_Mode = SNMPMode.Walk;
public SNMPMode SNMP_v1v2c_Mode
private SNMPMode _snmp_Mode = SNMPMode.Walk;
public SNMPMode SNMP_Mode
{
get { return _snmp_v1v2c_Mode; }
get { return _snmp_Mode; }
set
{
if (value == _snmp_v1v2c_Mode)
if (value == _snmp_Mode)
return;

_snmp_v1v2c_Mode = value;
_snmp_Mode = value;
SettingsChanged = true;
}
}

private SNMPVersion _snmp_v1v2c_Version = SNMPVersion.v2c;
public SNMPVersion SNMP_v1v2c_Version
private SNMPVersion _snmp_Version = SNMPVersion.v2c;
public SNMPVersion SNMP_Version
{
get { return _snmp_v1v2c_Version; }
get { return _snmp_Version; }
set
{
if (value == _snmp_v1v2c_Version)
if (value == _snmp_Version)
return;

_snmp_v1v2c_Version = value;
_snmp_Version = value;
SettingsChanged = true;
}
}

private bool _snmp_v1v2c_ExpandStatistics = true;
public bool SNMP_v1v2c_ExpandStatistics
private bool _snmp_ExpandStatistics = true;
public bool SNMP_ExpandStatistics
{
get { return _snmp_v1v2c_ExpandStatistics; }
get { return _snmp_ExpandStatistics; }
set
{
if (value == _snmp_v1v2c_ExpandStatistics)
if (value == _snmp_ExpandStatistics)
return;

_snmp_v1v2c_ExpandStatistics = value;
_snmp_ExpandStatistics = value;
SettingsChanged = true;
}
}

private ObservableCollection<string> _snmp_v3_HostHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_v3_HostHistory
private SNMPv3Security _snmp_Security = SNMPv3Security.authPriv;
public SNMPv3Security SNMP_Security
{
get { return _snmp_v3_HostHistory; }
get { return _snmp_Security; }
set
{
if (value == _snmp_v3_HostHistory)
if (value == _snmp_Security)
return;

_snmp_v3_HostHistory = value;
_snmp_Security = value;
SettingsChanged = true;
}
}

private ObservableCollection<string> _snmp_v3_OIDHistory = new ObservableCollection<string>();
public ObservableCollection<string> SNMP_v3_OIDHistory
private SNMPv3AuthenticationProvider _snmp_AuthenticationProvider = SNMPv3AuthenticationProvider.SHA1;
public SNMPv3AuthenticationProvider SNMP_AuthenticationProvider
{
get { return _snmp_v3_OIDHistory; }
get { return _snmp_AuthenticationProvider; }
set
{
if (value == _snmp_v3_OIDHistory)
if (value == _snmp_AuthenticationProvider)
return;

_snmp_v3_OIDHistory = value;
_snmp_AuthenticationProvider = value;
SettingsChanged = true;
}
}

private SNMPMode _snmp_v3_Mode = SNMPMode.Walk;
public SNMPMode SNMP_v3_Mode
private SNMPv3PrivacyProvider _snmp_PrivacyProvider = SNMPv3PrivacyProvider.AES;
public SNMPv3PrivacyProvider SNMP_PrivacyProvider
{
get { return _snmp_v3_Mode; }
get { return _snmp_PrivacyProvider; }
set
{
if (value == _snmp_v3_Mode)
if (value == _snmp_PrivacyProvider)
return;

_snmp_v3_Mode = value;
SettingsChanged = true;
}
}

private SNMPv3Security _snmp_v3_Security = SNMPv3Security.authPriv;
public SNMPv3Security SNMP_v3_Security
{
get { return _snmp_v3_Security; }
set
{
if (value == _snmp_v3_Security)
return;

_snmp_v3_Security = value;
SettingsChanged = true;
}
}

private SNMPv3AuthenticationProvider _snmp_v3_AuthenticationProvider = SNMPv3AuthenticationProvider.SHA1;
public SNMPv3AuthenticationProvider SNMP_v3_AuthenticationProvider
{
get { return _snmp_v3_AuthenticationProvider; }
set
{
if (value == _snmp_v3_AuthenticationProvider)
return;

_snmp_v3_AuthenticationProvider = value;
SettingsChanged = true;
}
}

private SNMPv3PrivacyProvider _snmp_v3_PrivacyProvider = SNMPv3PrivacyProvider.AES;
public SNMPv3PrivacyProvider SNMP_v3_PrivacyProvider
{
get { return _snmp_v3_PrivacyProvider; }
set
{
if (value == _snmp_v3_PrivacyProvider)
return;

_snmp_v3_PrivacyProvider = value;
SettingsChanged = true;
}
}

private bool _snmp_v3_ExpandStatistics = true;
public bool SNMP_v3_ExpandStatistics
{
get { return _snmp_v3_ExpandStatistics; }
set
{
if (value == _snmp_v3_ExpandStatistics)
return;

_snmp_v3_ExpandStatistics = value;
_snmp_PrivacyProvider = value;
SettingsChanged = true;
}
}
Expand Down
Loading

0 comments on commit 07ac7e4

Please sign in to comment.