<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SNMP &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/category/java/snmp/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Tue, 24 Mar 2015 17:18:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Generating TRAP in SNMP using SNMP4j</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/generating-trap-in-snmp-using-snmp4j/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/generating-trap-in-snmp-using-snmp4j/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 19:37:23 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[SNMP4J]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1582</guid>

					<description><![CDATA[Generating TRAP in SNMP using SNMP4j]]></description>
										<content:encoded><![CDATA[<p>As we have discussed, Traps are like events. This is a way the SNMP agent pushes the information to client. Asynchronously, events can be fired to client from server (agent).</p>
<p><span id="more-1582"></span> Example:</p>
<p><strong>SNMP Trap Receiver:</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Trap.receiver;

import java.io.IOException;

import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.CommunityTarget;
import org.snmp4j.MessageDispatcher;
import org.snmp4j.MessageDispatcherImpl;
import org.snmp4j.MessageException;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.mp.MPv1;
import org.snmp4j.mp.MPv2c;
import org.snmp4j.mp.StateReference;
import org.snmp4j.mp.StatusInformation;
import org.snmp4j.security.Priv3DES;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TcpAddress;
import org.snmp4j.smi.TransportIpAddress;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.transport.AbstractTransportMapping;
import org.snmp4j.transport.DefaultTcpTransportMapping;
import org.snmp4j.transport.DefaultUdpTransportMapping;
import org.snmp4j.util.MultiThreadedMessageDispatcher;
import org.snmp4j.util.ThreadPool;

public class TrapReceiver implements CommandResponder {
	public static void main(String&#x5B;] args) {
		TrapReceiver snmp4jTrapReceiver = new TrapReceiver();
		try {
			snmp4jTrapReceiver.listen(new UdpAddress(&quot;localhost/162&quot;));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Trap Listner
	 */
	public synchronized void listen(TransportIpAddress address)
			throws IOException {
		AbstractTransportMapping transport;
		if (address instanceof TcpAddress) {
			transport = new DefaultTcpTransportMapping((TcpAddress) address);
		} else {
			transport = new DefaultUdpTransportMapping((UdpAddress) address);
		}

		ThreadPool threadPool = ThreadPool.create(&quot;DispatcherPool&quot;, 10);
		MessageDispatcher mDispathcher = new MultiThreadedMessageDispatcher(
				threadPool, new MessageDispatcherImpl());

		// add message processing models
		mDispathcher.addMessageProcessingModel(new MPv1());
		mDispathcher.addMessageProcessingModel(new MPv2c());

		// add all security protocols
		SecurityProtocols.getInstance().addDefaultProtocols();
		SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());

		// Create Target
		CommunityTarget target = new CommunityTarget();
		target.setCommunity(new OctetString(&quot;public&quot;));

		Snmp snmp = new Snmp(mDispathcher, transport);
		snmp.addCommandResponder(this);

		transport.listen();
		System.out.println(&quot;Listening on &quot; + address);

		try {
			this.wait();
		} catch (InterruptedException ex) {
			Thread.currentThread().interrupt();
		}
	}

	/**
	 * This method will be called whenever a pdu is received on the given port
	 * specified in the listen() method
	 */
	public synchronized void processPdu(CommandResponderEvent cmdRespEvent) {
		System.out.println(&quot;Received PDU...&quot;);
		PDU pdu = cmdRespEvent.getPDU();
		if (pdu != null) {
			System.out.println(&quot;Trap Type = &quot; + pdu.getType());
			System.out.println(&quot;Variables = &quot; + pdu.getVariableBindings());
			}
		}
	}
</pre>
<p><strong>Version 1 Trap Sender:</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Trap.Sender;

import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.PDUv1;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.IpAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class TrapSenderVersion1 {

	public static final String community = &quot;public&quot;;

	// Sending Trap for sysLocation of RFC1213
	public static final String Oid = &quot;.1.3.6.1.2.1.1.8&quot;;

	//IP of Local Host
	public static final String ipAddress = &quot;127.0.0.1&quot;;

	//Ideally Port 162 should be used to send receive Trap, any other available Port can be used
	public static final int port = 162;

	public static void main(String&#x5B;] args) {
		TrapSenderVersion1 trapV1 = new TrapSenderVersion1();
		trapV1.sendTrap_Version1();
	}
	/**
	 * This methods sends the V1 trap to the Localhost in port 162
	 */
	public void sendTrap_Version1() {
		try {
			// Create Transport Mapping
			TransportMapping transport = new DefaultUdpTransportMapping();
			transport.listen();

			// Create Target
			CommunityTarget cTarget = new CommunityTarget();
			cTarget.setCommunity(new OctetString(community));
			cTarget.setVersion(SnmpConstants.version1);
			cTarget.setAddress(new UdpAddress(ipAddress + &quot;/&quot; + port));
			cTarget.setTimeout(5000);
			cTarget.setRetries(2);

			PDUv1 pdu = new PDUv1();
			pdu.setType(PDU.V1TRAP);
			pdu.setEnterprise(new OID(Oid));
			pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
			pdu.setSpecificTrap(1);
			pdu.setAgentAddress(new IpAddress(ipAddress));

			// Send the PDU
			Snmp snmp = new Snmp(transport);
			System.out.println(&quot;Sending V1 Trap... Check Wheather NMS is Listening or not? &quot;);
			snmp.send(pdu, cTarget);
			snmp.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
</pre>
<p><strong>Output:</strong></p>
<blockquote><p>Listening on 127.0.0.1/162<br />
Received PDU&#8230;<br />
Trap Type = -92<br />
Variables = []</p></blockquote>
<p><strong>Version 2 Trap Sender:</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Trap.Sender;

import java.util.Date;

import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.IpAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class TrapSenderVersion2 {

	public static final String community = &quot;public&quot;;

	// Sending Trap for sysLocation of RFC1213
	public static final String Oid = &quot;.1.3.6.1.2.1.1.8&quot;;

	//IP of Local Host
	public static final String ipAddress = &quot;127.0.0.1&quot;;

	//Ideally Port 162 should be used to send receive Trap, any other available Port can be used
	public static final int port = 162;

	public static void main(String&#x5B;] args) {
		TrapSenderVersion2 trapV2 = new TrapSenderVersion2();
		trapV2.sendTrap_Version2();
	}
	/**
	 * This methods sends the V1 trap to the Localhost in port 162
	 */
	public void sendTrap_Version2() {
		try {
			// Create Transport Mapping
			TransportMapping transport = new DefaultUdpTransportMapping();
			transport.listen();

			// Create Target
			CommunityTarget cTarget = new CommunityTarget();
			cTarget.setCommunity(new OctetString(community));
			cTarget.setVersion(SnmpConstants.version2c);
			cTarget.setAddress(new UdpAddress(ipAddress + &quot;/&quot; + port));
			cTarget.setRetries(2);
			cTarget.setTimeout(5000);

			// Create PDU for V2
			PDU pdu = new PDU();

			// need to specify the system up time
			pdu.add(new VariableBinding(SnmpConstants.sysUpTime,
					new OctetString(new Date().toString())));
			pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(
					Oid)));
			pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress,
					new IpAddress(ipAddress)));

			pdu.add(new VariableBinding(new OID(Oid), new OctetString(
					&quot;Major&quot;)));
			pdu.setType(PDU.NOTIFICATION);

			// Send the PDU
			Snmp snmp = new Snmp(transport);
			System.out.println(&quot;Sending V2 Trap... Check Wheather NMS is Listening or not? &quot;);
			snmp.send(pdu, cTarget);
			snmp.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
</pre>
<p><strong>Output:</strong></p>
<blockquote><p>Listening on 127.0.0.1/162<br />
Received PDU&#8230;<br />
Trap Type = -89<br />
Variables = [1.3.6.1.2.1.1.3.0 = Wed Feb 16 01:17:02 IST 2011, 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.2.1.1.6, 1.3.6.1.6.3.18.1.3.0 = 127.0.0.1, 1.3.6.1.2.1.1.6 = Major]</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/generating-trap-in-snmp-using-snmp4j/feed/</wfw:commentRss>
			<slash:comments>22</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1582</post-id>	</item>
		<item>
		<title>Creating SNMP Agent (Server) in JAVA using SNMP4j</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/creating-snmp-agent-server-in-java-using-snmp4j/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/creating-snmp-agent-server-in-java-using-snmp4j/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 18:44:18 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[SNMP4J]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1576</guid>

					<description><![CDATA[Creating SNMP Agent (Server) in JAVA using SNMP4j]]></description>
										<content:encoded><![CDATA[<p>In Previous article, we have seen that how to <a title="Create SNMP Client in JAVA using SNMP4j" href="https://jitendrazaa.com/blog/java/snmp/create-snmp-client-in-java-using-snmp4j/" target="_blank">create SNMP client in JAVA using SNMP4j</a>.</p>
<p style="text-align: justify;">To create the Agent for SNMP which listens for the request should extend the abstract class <strong>BaseAgent</strong>.<br />
The BaseAgent abstract class defines a framework for writing SNMP agents using the <strong>SNMP4J-Agent API</strong>. To implement your own SNMP agent, extend this class and implement the abstract methods defined by BaseAgent. The hook methods do not need any specific implementation. They only provide a defined mechanism to customize your agent.</p>
<p><strong><span id="more-1576"></span>Below Class is used to create the SNMP Agent:</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Server;

import java.io.File;
import java.io.IOException;

import org.snmp4j.TransportMapping;
import org.snmp4j.agent.BaseAgent;
import org.snmp4j.agent.CommandProcessor;
import org.snmp4j.agent.DuplicateRegistrationException;
import org.snmp4j.agent.MOGroup;
import org.snmp4j.agent.ManagedObject;
import org.snmp4j.agent.mo.MOTableRow;
import org.snmp4j.agent.mo.snmp.RowStatus;
import org.snmp4j.agent.mo.snmp.SnmpCommunityMIB;
import org.snmp4j.agent.mo.snmp.SnmpNotificationMIB;
import org.snmp4j.agent.mo.snmp.SnmpTargetMIB;
import org.snmp4j.agent.mo.snmp.StorageType;
import org.snmp4j.agent.mo.snmp.VacmMIB;
import org.snmp4j.agent.security.MutableVACM;
import org.snmp4j.mp.MPv3;
import org.snmp4j.security.SecurityLevel;
import org.snmp4j.security.SecurityModel;
import org.snmp4j.security.USM;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.Variable;
import org.snmp4j.transport.TransportMappings;

public class SNMPAgent extends BaseAgent {

	private String address;

	/**
	 *
	 * @param address
	 * @throws IOException
	 */
	public SNMPAgent(String address) throws IOException {

		/**
		 * Creates a base agent with boot-counter, config file, and a
		 * CommandProcessor for processing SNMP requests. Parameters:
		 * &quot;bootCounterFile&quot; - a file with serialized boot-counter information
		 * (read/write). If the file does not exist it is created on shutdown of
		 * the agent. &quot;configFile&quot; - a file with serialized configuration
		 * information (read/write). If the file does not exist it is created on
		 * shutdown of the agent. &quot;commandProcessor&quot; - the CommandProcessor
		 * instance that handles the SNMP requests.
		 */
		super(new File(&quot;conf.agent&quot;), new File(&quot;bootCounter.agent&quot;),
				new CommandProcessor(
						new OctetString(MPv3.createLocalEngineID())));
		this.address = address;
	}

	/**
	 * Adds community to security name mappings needed for SNMPv1 and SNMPv2c.
	 */
	@Override
	protected void addCommunities(SnmpCommunityMIB communityMIB) {
		Variable&#x5B;] com2sec = new Variable&#x5B;] { new OctetString(&quot;public&quot;),
				new OctetString(&quot;cpublic&quot;), // security name
				getAgent().getContextEngineID(), // local engine ID
				new OctetString(&quot;public&quot;), // default context name
				new OctetString(), // transport tag
				new Integer32(StorageType.nonVolatile), // storage type
				new Integer32(RowStatus.active) // row status
		};
		MOTableRow row = communityMIB.getSnmpCommunityEntry().createRow(
				new OctetString(&quot;public2public&quot;).toSubIndex(true), com2sec);
		communityMIB.getSnmpCommunityEntry().addRow(row);

	}

	/**
	 * Adds initial notification targets and filters.
	 */
	@Override
	protected void addNotificationTargets(SnmpTargetMIB arg0,
			SnmpNotificationMIB arg1) {
		// TODO Auto-generated method stub

	}

	/**
	 * Adds all the necessary initial users to the USM.
	 */
	@Override
	protected void addUsmUser(USM arg0) {
		// TODO Auto-generated method stub

	}

	/**
	 * Adds initial VACM configuration.
	 */
	@Override
	protected void addViews(VacmMIB vacm) {
		vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString(
				&quot;cpublic&quot;), new OctetString(&quot;v1v2group&quot;),
				StorageType.nonVolatile);

		vacm.addAccess(new OctetString(&quot;v1v2group&quot;), new OctetString(&quot;public&quot;),
				SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV,
				MutableVACM.VACM_MATCH_EXACT, new OctetString(&quot;fullReadView&quot;),
				new OctetString(&quot;fullWriteView&quot;), new OctetString(
						&quot;fullNotifyView&quot;), StorageType.nonVolatile);

		vacm.addViewTreeFamily(new OctetString(&quot;fullReadView&quot;), new OID(&quot;1.3&quot;),
				new OctetString(), VacmMIB.vacmViewIncluded,
				StorageType.nonVolatile);

	}

	/**
	 * Unregister the basic MIB modules from the agent's MOServer.
	 */
	@Override
	protected void unregisterManagedObjects() {
		// TODO Auto-generated method stub

	}

	/**
	 * Register additional managed objects at the agent's server.
	 */
	@Override
	protected void registerManagedObjects() {
		// TODO Auto-generated method stub

	}

	protected void initTransportMappings() throws IOException {
		transportMappings = new TransportMapping&#x5B;1];
		Address addr = GenericAddress.parse(address);
		TransportMapping tm = TransportMappings.getInstance()
				.createTransportMapping(addr);
		transportMappings&#x5B;0] = tm;
	}

	/**
	 * Start method invokes some initialization methods needed to start the
	 * agent
	 *
	 * @throws IOException
	 */
	public void start() throws IOException {

		init();
		// This method reads some old config from a file and causes
		// unexpected behavior.
		// loadConfig(ImportModes.REPLACE_CREATE);
		addShutdownHook();
		getServer().addContext(new OctetString(&quot;public&quot;));
		finishInit();
		run();
		sendColdStartNotification();
	}

	/**
	 * Clients can register the MO they need
	 */
	public void registerManagedObject(ManagedObject mo) {
		try {
			server.register(mo, null);
		} catch (DuplicateRegistrationException ex) {
			throw new RuntimeException(ex);
		}
	}

	public void unregisterManagedObject(MOGroup moGroup) {
		moGroup.unregisterMOs(server, getContext(moGroup));
	}

}
</pre>
<p><strong> This class is used to create ManagedObject which is used by the SNMP agent Class created above:</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Server;

import org.snmp4j.agent.mo.MOAccessImpl;
import org.snmp4j.agent.mo.MOScalar;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.Variable;

/**
 * This class creates and returns ManagedObjects
 * @author Shiva
 *
 */
public class MOCreator {
	public static MOScalar createReadOnly(OID oid,Object value ){
		return new MOScalar(oid,
				MOAccessImpl.ACCESS_READ_ONLY,
				getVariable(value));
	}

	private static Variable getVariable(Object value) {
		if(value instanceof String) {
			return new OctetString((String)value);
		}
		throw new IllegalArgumentException(&quot;Unmanaged Type: &quot; + value.getClass());
	}

}
</pre>
<p><strong> Below class tests that agent is working properly or not :</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.G2.SNMP.Server;

import java.io.IOException;

import org.snmp4j.smi.OID;

import com.G2.SNMP.client.SNMPManager;

public class TestSNMPAgent {

	static final OID sysDescr = new OID(&quot;.1.3.6.1.2.1.1.1.0&quot;);

	public static void main(String&#x5B;] args) throws IOException {
		TestSNMPAgent client = new TestSNMPAgent(&quot;udp:127.0.0.1/161&quot;);
		client.init();
	}

	SNMPAgent agent = null;
	/**
	 * This is the client which we have created earlier
	 */
	SNMPManager client = null;

	String address = null;

	/**
	 * Constructor
	 *
	 * @param add
	 */
	public TestSNMPAgent(String add) {
		address = add;
	}

	private void init() throws IOException {
		agent = new SNMPAgent(&quot;0.0.0.0/2001&quot;);
		agent.start();

		// Since BaseAgent registers some MIBs by default we need to unregister
		// one before we register our own sysDescr. Normally you would
		// override that method and register the MIBs that you need
		agent.unregisterManagedObject(agent.getSnmpv2MIB());

		// Register a system description, use one from you product environment
		// to test with
		agent.registerManagedObject(MOCreator.createReadOnly(sysDescr,
				&quot;This Description is set By ShivaSoft&quot;));

		// Setup the client to use our newly started agent
		client = new SNMPManager(&quot;udp:127.0.0.1/2001&quot;);
		client.start();
		// Get back Value which is set
		System.out.println(client.getAsString(sysDescr));
	}

}
</pre>
<p><strong> Output :</strong></p>
<blockquote><p>This Description is set By ShivaSoft</p></blockquote>
<p><strong>Possible run time errors :</strong><br />
Few of you may receive error like</p>
<blockquote><p>&#8220;Exception in thread &#8220;main&#8221; java.lang.RuntimeException: java.net.BindException: Address already in use: Cannot bind&#8221;.</p></blockquote>
<p><strong>Solution:</strong> You are trying to listen on a local IP and port which is already in use by some other process (for example the operating system &#8211; if you use port 161 this is rather likely).</p>
<p>Try to use a different port (or IP address &#8211; but most services listen on all local IP addresses) or stop the process that is using it.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/creating-snmp-agent-server-in-java-using-snmp4j/feed/</wfw:commentRss>
			<slash:comments>34</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1576</post-id>	</item>
		<item>
		<title>Create SNMP Client in JAVA Using SNMP4j</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/create-snmp-client-in-java-using-snmp4j/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/create-snmp-client-in-java-using-snmp4j/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 17:22:06 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[SNMP4J]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1571</guid>

					<description><![CDATA[Create SNMP Client in JAVA Using SNMP4j]]></description>
										<content:encoded><![CDATA[<p>There are lots of open source library for SNMP is available, even java have library for the same,  But in this article I will explain a simple example of using SNMP4j in JAVA to create a simple client which will display the hardware information.</p>
<p><strong>Note : </strong>To run this program, SNMP service must be installed. <a title="Install SNMP in Windows XP" href="https://www.jitendrazaa.com/blog/java/snmp/install-snmp-service-in-windows-xp-and-overview-of-mib-explorer/" target="_blank">Check this article to know that how to install SNMP in Windows XP.</a></p>
<p>Download libraries from <a title="Download SNMP4j Library" href="http://www.snmp4j.org/html/download.html" target="_blank">http://www.snmp4j.org/html/download.html</a></p>
<p><strong>Create Simple NMS (Network management station / Client) in JAVA using SNMP4j:<span id="more-1571"></span></strong></p>
<pre class="brush: java; title: ; notranslate">

package com.G2.SNMP.client;

import java.io.IOException;

import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class SNMPManager {

Snmp snmp = null;
String address = null;

/**
* Constructor
* @param add
*/
public SNMPManager(String add)
{
address = add;
}

public static void main(String&#x5B;] args) throws IOException {
/**
* Port 161 is used for Read and Other operations
* Port 162 is used for the trap generation
*/
SNMPManager client = new SNMPManager(&quot;udp:127.0.0.1/161&quot;);
client.start();
/**
* OID - .1.3.6.1.2.1.1.1.0 =&gt; SysDec
* OID - .1.3.6.1.2.1.1.5.0 =&gt; SysName
* =&gt; MIB explorer will be usefull here, as discussed in previous article
*/
String sysDescr = client.getAsString(new OID(&quot;.1.3.6.1.2.1.1.1.0&quot;));
System.out.println(sysDescr);
}

/**
* Start the Snmp session. If you forget the listen() method you will not
* get any answers because the communication is asynchronous
* and the listen() method listens for answers.
* @throws IOException
*/
private void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
// Do not forget this line!
transport.listen();
}

/**
* Method which takes a single OID and returns the response from the agent as a String.
* @param oid
* @return
* @throws IOException
*/
public String getAsString(OID oid) throws IOException {
ResponseEvent event = get(new OID&#x5B;] { oid });
return event.getResponse().get(0).getVariable().toString();
}

/**
* This method is capable of handling multiple OIDs
* @param oids
* @return
* @throws IOException
*/
public ResponseEvent get(OID oids&#x5B;]) throws IOException {
PDU pdu = new PDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {
return event;
}
throw new RuntimeException(&quot;GET timed out&quot;);
}

/**
* This method returns a Target, which contains information about
* where the data should be fetched and how.
* @return
*/
private Target getTarget() {
Address targetAddress = GenericAddress.parse(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(&quot;public&quot;));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
return target;
}

}
</pre>
<p><strong>Output:</strong></p>
<blockquote><p>Hardware: x86 Family 6 Model 23 Stepping 10 AT/AT COMPATIBLE &#8211; Software: Windows 2000 Version 5.1 (Build 2600 Multiprocessor Free)</p></blockquote>
<p>Explanation of every method is documented in above program. In Next article, we will write a Java Program to create SNMP Agent.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/create-snmp-client-in-java-using-snmp4j/feed/</wfw:commentRss>
			<slash:comments>78</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1571</post-id>	</item>
		<item>
		<title>Install SNMP Service in Windows XP and Overview of MIB Explorer</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/install-snmp-service-in-windows-xp-and-overview-of-mib-explorer/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/install-snmp-service-in-windows-xp-and-overview-of-mib-explorer/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 15:19:59 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Windows XP]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1563</guid>

					<description><![CDATA[Install SNMP Service in Windows XP and Overview of MIB Explorer]]></description>
										<content:encoded><![CDATA[<p><strong>Enable SNMP services in Windows Xp:</strong></p>
<ol>
<li>To open the Windows Components Wizard, click <strong>Start</strong>, click <strong>Control Pane</strong>l, double-click<strong> Add or Remove Programs</strong>, and then click <strong>Add/Remove Windows Components</strong>.</li>
<li>In Components, click <strong>Management and Monitoring Tools</strong> (but do not select or clear its check box), and then click <strong>Details</strong>.</li>
<li>Select the<strong> Simple Network Management Protocol</strong> check box, and click OK.</li>
<li>Click <strong>Next</strong>.</li>
</ol>
<figure id="attachment_1565" aria-describedby="caption-attachment-1565" style="width: 440px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Install-SNMP-Service-in-Windows-XP.jpg?ssl=1"><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="wp-image-1565 size-full" title="Install SNMP Service in Windows XP" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Install-SNMP-Service-in-Windows-XP.jpg?resize=440%2C202&#038;ssl=1" alt="Install SNMP Service in Windows XP" width="440" height="202" /></a><figcaption id="caption-attachment-1565" class="wp-caption-text">Install SNMP Service in Windows XP</figcaption></figure>
<p><strong><span id="more-1563"></span>Overview of MIB Explorer:</strong><br />
There are lots of tools available to view the MIB structure of <strong>SNMP Agent</strong>.</p>
<figure id="attachment_1566" aria-describedby="caption-attachment-1566" style="width: 440px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/MIB-Management-Information-Base.png?ssl=1"><img data-recalc-dims="1" decoding="async" class="  wp-image-1566 size-full" title="MIB - Management Information Base Explorer" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/MIB-Management-Information-Base.png?resize=440%2C146&#038;ssl=1" alt="MIB - Management Information Base Explorer" width="440" height="146" /></a><figcaption id="caption-attachment-1566" class="wp-caption-text">MIB &#8211; Management Information Base Explorer</figcaption></figure>
<p><a title="MIB Explorer" href="http://www.serverscheck.in/mib_browser/download.asp" target="_blank">Download this tool from internet which is freely available.</a></p>
<p>Above tool is very useful in finding the<strong> Object Identifiers</strong>.</p>
<p>As shown in above figure, enter the IP address of the SNMP agent and select the Operation.  OID can be selected from left tree and the information related to that OID is displayed in the Grid.</p>
<p>Using this tool, anyone can check the functionality of code written by them against the output of this tool.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/install-snmp-service-in-windows-xp-and-overview-of-mib-explorer/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1563</post-id>	</item>
		<item>
		<title>Terminologies used in SNMP</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/terminologies-used-in-snmp/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/terminologies-used-in-snmp/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Tue, 22 Feb 2011 19:16:30 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1554</guid>

					<description><![CDATA[Terminologies used in SNMP]]></description>
										<content:encoded><![CDATA[<p><a title="SNMP Introduction" href="https://jitendrazaa.com/blog/java/snmp/introduction-to-snmp/" target="_blank">In Previous article</a>, we have seen that what actually is SNMP.  In this article we will discuss on different terminologies used in SNMP.</p>
<p><strong>(1)  SNMP</strong></p>
<ul>
<li>Application-layer protocol for managing TCP/IP based networks.</li>
<li>Runs over UDP, which runs over IP</li>
</ul>
<p><strong> (2)  NMS (Network Management Station)</strong></p>
<ul>
<li>Device that pools SNMP agent for info (Client)</li>
</ul>
<p><strong> (3)  SNMP Agent</strong></p>
<ul>
<li>Device (e.g. Router) running software that understands SNMP language. You can imagine like a Server.</li>
</ul>
<p><strong> (4)  MIB</strong></p>
<ul>
<li>Database of info conforming to SMI.</li>
</ul>
<p><strong> (5)  SMI (Structure of Management Information)</strong></p>
<ul>
<li>Standard that defines how to create a MIB.</li>
</ul>
<p><strong> (6) Trap:</strong></p>
<ul>
<li>Traps are like events. This is a way the SNMP agent pushes the information to client. Asynchronously, events can be fired to client from server (agent).</li>
</ul>
<p><strong> (7) Ports:</strong></p>
<ul>
<li>The SNMP agent receives requests on UDP<strong> port 161</strong>. The manager may send requests from any available source port to port 161 in the agent. The agent response will be sent back to the source port on the manager. The manager receives notifications (Traps and InformRequests) on <strong>port 162</strong>. The agent may generate notifications from any available port.<span id="more-1554"></span></li>
</ul>
<p><strong>There are basically 5 commands supported by SNMP:</strong></p>
<ol>
<li>GetRequest, aka Get</li>
<li>GetNextRequest, aka GetNext</li>
<li>GetResponse, aka Response</li>
<li> SetRequest, aka Set</li>
<li>Trap</li>
</ol>
<p>In next article, we will discuss that how to start the SNMP in <a title="Install SNMP Service in Windows XP and Overview of MIB Explorer" href="https://jitendrazaa.com/blog/java/snmp/install-snmp-service-in-windows-xp-and-overview-of-mib-explorer/" target="_blank">Windows XP and Overview of MIB explorer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/terminologies-used-in-snmp/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1554</post-id>	</item>
		<item>
		<title>Introduction to SNMP</title>
		<link>https://www.jitendrazaa.com/blog/java/snmp/introduction-to-snmp/</link>
					<comments>https://www.jitendrazaa.com/blog/java/snmp/introduction-to-snmp/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Tue, 22 Feb 2011 19:02:06 +0000</pubDate>
				<category><![CDATA[SNMP]]></category>
		<category><![CDATA[JAVA]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1548</guid>

					<description><![CDATA[Introduction to SNMP in JAVA]]></description>
										<content:encoded><![CDATA[<p>SNMP stands for <strong><a title="Good Introduction to SNMP" href="http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol" target="_blank">Simple Network Management Protocol</a></strong> &#8211; and is one of the most widely spread internet management protocols. It is based on UDP and uses <strong><a title="Basic Encoding Rules" href="http://en.wikipedia.org/wiki/Basic_encoding_rules" target="_blank">BER (Basic Encoding Rules)</a></strong> for encoding.</p>
<p>SNMP is an internet technology &#8211; specified by means of <a title="Request for Comments" href="http://en.wikipedia.org/wiki/Request_For_Comments" target="_blank">RFCs (Requests For Comments)</a>, which are issued through the <a title="The Internet Engineering Task Force (IETF)" href="http://www.ietf.org/" target="_blank">Internet Engineering Task Force (IETF)</a>.</p>
<p>SNMP defines both how to structure management information (data model exposed for management), and how to access it (protocol). According to SNMP, the management information is structured into <strong>MIBs (Management Information Bases)</strong>. A MIB is defined using a formal language called <strong>Structure of Management Information (SMI)</strong> &#8211; whose syntax uses a subset of <a title="Abstract Syntax Notation One" href="http://en.wikipedia.org/wiki/ASN.1" target="_blank"><strong>ASN.1 (Abstract Syntax Notation 1)</strong>.</a><span id="more-1548"></span></p>
<p>When dealing with remote devices, there should be some standard to understand the information stored in the SNMP agent. SNMP accomplishes that through MIB.</p>
<p>The basic verbs of the SNMP protocol are <strong>GET</strong>, <strong>SET</strong>, and <strong>GETNEXT </strong>(SNMPv2 adds GETBULK). An SNMP entity can also send asynchronous events (a <strong>TRAP </strong>in SNMPv1, a <strong>NOTIFICATION </strong>or an <strong>INFORM </strong>in SNMPv2). What you GET and SET are individual variables of simple types (to simplify, strings/integers/enumerations) which can be either scalar &#8211; or located in tables.</p>
<p><strong>OBJECT-IDENTIFIERS</strong> are at the root of the Structure of Management Information (SMI) used to describe SNMP data.<br />
To make it brief, an OBJECT-IDENTIFIER or OID identifies a node in a global tree whose arcs (segments between parent and child nodes) are identified by numbers.</p>
<p>All SNMP definitions &#8211; MIBs, objects, etc&#8230; are identified by their OID in this global tree. The root of the OID tree is defined by the ASN.1 standard, and has three nodes at its first level <strong>iso, ccitt</strong> and <strong>joint-iso-ccitt</strong>.</p>
<p><strong><a href="http://en.wikipedia.org/wiki/Internet_Assigned_Numbers_Authority" target="_blank">The IANA (Internet Assigned Numbers Authority)</a></strong> is responsible for the allocation of these subnodes. And the subnode owned by <strong>Sun Microsystems is forty two</strong>, leading to the OID:</p>
<blockquote><p>sun OBJECT IDENTIFIER ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) 42 }</p></blockquote>
<p>Usually, such an OID would be written &#8211; in what we call the dot notation, as: <strong>.3.6.1.4.1.42</strong></p>
<p>In fact, Sun Microsystems is responsible for the allocation of any node that falls under the branch:</p>
<blockquote><p>sun OBJECT IDENTIFIER ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) 42 }</p></blockquote>
<p>Example of MIB:</p>
<figure id="attachment_1552" aria-describedby="caption-attachment-1552" style="width: 454px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Structure-of-MIB-SNMP.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-full wp-image-1552" title="Structure of MIB SNMP" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Structure-of-MIB-SNMP.jpg?resize=454%2C487&#038;ssl=1" alt="Structure of MIB SNMP" width="454" height="487" /></a><figcaption id="caption-attachment-1552" class="wp-caption-text">Structure of MIB in SNMP</figcaption></figure>
<blockquote><p>iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) system(1) is readed as:<br />
1.3.6.1.2.1.1</p></blockquote>
<p>In next article, we will see the <a title="Terminologies used in SNMP" href="https://jitendrazaa.com/blog/tips/terminologies-used-in-snmp/" target="_blank">terminologies used in SNMP</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/snmp/introduction-to-snmp/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1548</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-04-21 08:41:38 by W3 Total Cache
-->