高手帮我看一下snmp服务开发的这段代码
private static Dictionary<string, string> getWalkValue(string host, string irootOid){
Dictionary<string, string> dic = new Dictionary<string, string>();
// SNMP community name
OctetString community = new OctetString("matherfucker");
// Define agent parameters class
AgentParameters param = new AgentParameters(community);
// Set SNMP version to 2 (GET-BULK only works with SNMP ver 2 and 3)
param.Version = SnmpVersion.Ver2;
// Construct the agent address object
// IpAddress class is easy to use here because
// it will try to resolve constructor parameter if it doesn't
// parse to an IP address
IpAddress agent = new IpAddress(host);
// Construct target
UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
// Define Oid that is the root of the MIB
// tree you wish to retrieve
Oid rootOid = new Oid(irootOid); // ifDescr
// This Oid represents last Oid returned by
// the SNMP agent
Oid lastOid = (Oid)rootOid.Clone();
// Pdu class used for all requests
Pdu pdu = new Pdu(PduType.GetBulk);
// In this example, set NonRepeaters value to 0
pdu.NonRepeaters = 0;
// MaxRepetitions tells the agent how many Oid/Value pairs to return
// in the response.
pdu.MaxRepetitions = 5;
// Loop through results
while (lastOid != null)
{
// When Pdu class is first constructed, RequestId is set to 0
// and during encoding id will be set to the random value
// for subsequent requests, id will be set to a value that
// needs to be incremented to have unique request ids for each
// packet
if (pdu.RequestId != 0)
{
pdu.RequestId += 1;
}
// Clear Oids from the Pdu class.
pdu.VbList.Clear();
// Initialize request PDU with the last retrieved Oid
pdu.VbList.Add(lastOid);
// Make SNMP request
SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);
// You should catch exceptions in the Request if using in real application.
// If result is null then agent didn't reply or we couldn't parse the reply.
if (result != null)
{
// ErrorStatus other then 0 is an error returned by
// the Agent - see SnmpConstants for error definitions
if (result.Pdu.ErrorStatus == 0)
{
// Walk through returned variable bindings
foreach (Vb v in result.Pdu.VbList)
{
// Check that retrieved Oid is "child" of the root OID
if (rootOid.IsRootOf(v.Oid))
{
dic.Add(v.Oid.ToString(), v.Value.ToString());
}
else
{
// we have reached the end of the requested
// MIB tree. Set lastOid to null and exit loop
lastOid = null;
}
}
}
}
}
target.Close();
return dic;
}
这里需要通过snmp服务远程获得服务器的基本信息,网络流量等,但是irootOid这个参数不清楚怎么使用,这个函数getWalkValue也看不是太清楚,有没有达人帮帮我! --------------------编程问答-------------------- 没人帮我呀! --------------------编程问答-------------------- oid是路由交换设备的标示,不同厂家oid参数不同,你可以上网查看,比如思科,化为等,知道标示才可以获取交换机上的MIB,MIB里包含交换数据。 --------------------编程问答-------------------- rootOid你可以传"1.3.6.1"或".1.3.6.1",几乎所有的Oid都在该条目下。
其中:iso(1),identified-organization(3),dod(6),internet(1) --------------------编程问答--------------------
传入的是这个值,但是在SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);这一行还是抛错 未处理 SnmpSharpNet.SnmpException
Message=Request has reached maximum retries.
Source=SnmpSharpNet
ErrorCode=12
兄弟,帮忙再看一下吧!
补充:.NET技术 , C#