PoshCode Logo PowerShell Code Repository

Send SNMP trap by halr9000 27 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1413"></script>download | new post

This will send an SNMP trap to the specified manager (hostname). The script isn’t very flexible, but it’s a good example of how to build traps using SharpSNMPLib. External requirementss:

  1. Param ( $DestinationHost )
  2. Add-Type -Path "C:\Program Files\LeXtudio Software\sharpsnmplib.dll"
  3. Add-Type -Path "C:\Program Files\LeXtudio Software\SharpSnmpLib.Controls.dll"
  4. $manager = [system.Net.Dns]::Resolve( $DestinationHost ).AddressList[0]
  5. $TrapDest = New-Object Net.IPEndPoint( $manager, 162 )
  6.  
  7. [Lextm.SharpSnmpLib.Messaging.Messenger]::SendTrapV1( $TrapDest,
  8.         [IPAddress]::Loopback,
  9.         [Lextm.SharpSnmpLib.OctetString]"public",
  10.         [Lextm.SharpSnmpLib.ObjectIdentifier]"1.3.6",
  11.         [Lextm.SharpSnmpLib.GenericCode]::ColdStart,
  12.         0,
  13.         0,
  14.         ( New-GenericObject.ps1 system.collections.generic.list lextm.sharpsnmplib.variable )
  15. )

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me