The SNMPAgent class is used to implement UDP-based SNMP Agent Applications.
ipworkssnmp_snmpagent_open(); ipworkssnmp_snmpagent_close($res); ipworkssnmp_snmpagent_register_callback($res, $id, $function); ipworkssnmp_snmpagent_get_last_error($res); ipworkssnmp_snmpagent_get_last_error_code($res); ipworkssnmp_snmpagent_set($res, $id, $index, $value); ipworkssnmp_snmpagent_get($res, $id, $index); ipworkssnmp_snmpagent_do_adduser($res, $user, $authenticationprotocol, $authenticationpassword, $encryptionalgorithm, $encryptionpassword); ipworkssnmp_snmpagent_do_clearcache($res); ipworkssnmp_snmpagent_do_config($res, $configurationstring); ipworkssnmp_snmpagent_do_doevents($res); ipworkssnmp_snmpagent_do_hashpasswords($res); ipworkssnmp_snmpagent_do_removeuser($res, $user); ipworkssnmp_snmpagent_do_reset($res); ipworkssnmp_snmpagent_do_sendresponse($res, $remotehost, $remoteport, $requestid, $community, $errorstatus, $errorindex); ipworkssnmp_snmpagent_do_sendsecureresponse($res, $remotehost, $remoteport, $requestid, $messageid, $errorstatus, $errorindex, $user, $authenticationprotocol, $authenticationpassword, $encryptionalgorithm, $encryptionpassword); ipworkssnmp_snmpagent_do_sendsecuretrap($res, $remotehost, $trapoid, $user, $authenticationprotocol, $authenticationpassword, $encryptionalgorithm, $encryptionpassword); ipworkssnmp_snmpagent_do_sendtrap($res, $remotehost, $trapoid); ipworkssnmp_snmpagent_do_showcache($res); ipworkssnmp_snmpagent_do_value($res, $oid);
The SNMPAgent class implements a UDP-based standard SNMP Agent as specified in the SNMP RFCs. The class supports SNMP v1, v2c, and v3.
The class provides both encoding/decoding and transport capabilities, making the task of developing a custom SNMP agent as simple as setting a few key properties and handling a few events. SNMP data such as SNMP object id-s (OID-s) are exchanged as text strings, thus further simplifying the task of handling them.
The class is activated/deactivated by setting the Active property. This property enables or disables sending and receiving.
The class operates asynchronously. Requests are received through events such as GetRequest, GetBulkRequest, GetNextRequest, etc. and the corresponding responses are automatically sent when the events return. Traps are sent through the SendTrap method.
SNMPv3 USM security passwords are requested through the GetUserPassword event, and event parameters such as User and SecurityLevel provide information about the security attributes of received requests, and enable granular decision capability about what to provide and what not to provide. The SendSecureTrap method is used to send authenticated (secure) SNMPv3 traps.
The AddUser, RemoveUser, ShowCache, and ClearCache methods are used to manage an internal authentication cache. This internal cache can be used as an alternative to the GetUserPassword event, automatically checking the cache against the security parameters provided in the request signature.
SNMP OIDs, types, and values are provided in the Objects collection of SNMP objects for both sent and received packets.
Other packet information is provided through corresponding event parameters, such as Community, or RequestId.
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
|AcceptData||Enables or disables data reception.|
|Active||Enables or disables sending and receiving of SNMP packets.|
|LocalEngineId||The Engine Id of the SNMP Agent.|
|LocalHost||The name of the local host or user-assigned IP interface through which connections are initiated or accepted.|
|LocalPort||The port in the local host where the class listens.|
|ObjCount||The number of records in the Obj arrays.|
|ObjType||The current object's type.|
|ObjId||The current object's id which is encoded as a string of numbers separated by periods.|
|ObjTypeString||A string representation of the current object's ObjectType .|
|ObjValue||The current object's value.|
|RequestId||The request-id to mark outgoing packets with.|
|SNMPVersion||Version of SNMP used for outgoing requests (traps).|
|SysUpTime||Time passed since the agent was initialized (in hundredths of a second).|
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
|AddUser||Adds a user to the internal authentication cache.|
|ClearCache||Clears the internal authentication database.|
|Config||Sets or retrieves a configuration setting.|
|DoEvents||Processes events from the internal message queue.|
|HashPasswords||Hashes all passwords in the cache.|
|RemoveUser||Removes the user specified by User from the internal authentication cache.|
|Reset||Clears the object arrays.|
|SendResponse||Sends a response packet to a Get, Get-Next, Get-Bulk, or Set request.|
|SendSecureResponse||Sends an authenticated and/or encrypted SNMPv3 response.|
|SendSecureTrap||Sends an authenticated and/or encrypted SNMPv3 trap.|
|SendTrap||Sends an SNMP Trap.|
|ShowCache||Lists all entries in the internal user authentication cache.|
|Value||Returns the value corresponding to an OID.|
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
|BadPacket||Fired for erroneous and/or malformed messages.|
|CacheEntry||Shows in the internal cache.|
|DiscoveryRequest||Fired when an SNMPv3 discovery packet is received.|
|Error||Information about errors during data delivery.|
|GetBulkRequest||Fired when a GetBulkRequest packet is received.|
|GetNextRequest||Fired when a GetNextRequest packet is received.|
|GetRequest||Fired when a GetRequest packet is received.|
|GetUserPassword||Retrieves a password associated with a user.|
|GetUserSecurityLevel||Sets the security level for an incoming packet.|
|HashPassword||Fired before and after a password is hashed.|
|PacketTrace||Fired for every packet sent or received.|
|ReadyToSend||Fired when the class is ready to send data.|
|Report||Fired when a Report packet is received.|
|SetRequest||Fired when a SetRequest packet is received.|
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
|AuthenticationKey||The key to use for authentication.|
|CompatibilityMode||Whether to operate the class in a specific compatibility mode.|
|ContextEngineId||Sets the context engine id of the SNMP entity.|
|ContextName||Sets the context name of the SNMP entity.|
|EncryptionKey||The key to use for encryption.|
|ForceLocalPort||Forces the class to bind to a specific port.|
|MsgMaxSize||The maximum supported message size.|
|RespondFromDestIP||Whether to respond from the IP address that the request was sent to.|
|SourceAddress||The source address of the received packet.|
|SourcePort||The source port of the received packet.|
|TimeWindow||The time window used for SNMPv3 timeliness checking (authentication).|
|TrapAgentAddress||The address of the object generating the trap.|
|TrapCommunity||The value of the Community parameter for SNMP traps.|
|TrapEnterprise||The type of the object generating the trap.|
|TrapPort||The port where SNMP traps are sent.|
|CaptureIPPacketInfo||Used to capture the packet information.|
|DestinationAddress||Used to get the destination address from the packet information.|
|DontFragment||Used to set the Don't Fragment flag of outgoing packets.|
|LocalHost||The name of the local host through which connections are initiated or accepted.|
|LocalPort||The port in the local host where the class binds.|
|MaxPacketSize||The maximum length of the packets that can be received.|
|QOSDSCPValue||Used to specify an arbitrary QOS/DSCP setting (optional).|
|QOSTrafficType||Used to specify QOS/DSCP settings (optional).|
|ShareLocalPort||If set to True, allows more than one instance of the class to be active on the same local port.|
|SourceIPAddress||Used to set the source IP address used when sending a packet.|
|SourceMacAddress||Used to set the source MAC address used when sending a packet.|
|UseConnection||Determines whether to use a connected socket.|
|UseIPv6||Whether or not to use IPv6.|
|AbsoluteTimeout||Determines whether timeouts are inactivity timeouts or absolute timeouts.|
|FirewallData||Used to send extra data to the firewall.|
|InBufferSize||The size in bytes of the incoming queue of the socket.|
|OutBufferSize||The size in bytes of the outgoing queue of the socket.|
|BuildInfo||Information about the product's build.|
|CodePage||The system code page used for Unicode to Multibyte translations.|
|LicenseInfo||Information about the current license.|
|ProcessIdleEvents||Whether the class uses its internal event loop to process events when the main thread is idle.|
|SelectWaitMillis||The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.|
|UseInternalSecurityAPI||Tells the class whether or not to use the system security libraries or an internal implementation.|