我想用SnmpSharpNet 获取路由器的mac地址,现在只能获取到sysDescr等叶子节点的信息,如何获得mac地址啊?
请各位大侠帮忙~~
private void button1_Click(object sender, EventArgs e)
{
// SNMP community name
OctetString community = new OctetString("public");
AgentParameters param = new AgentParameters(community);
param.Version = SnmpVersion.Ver1;
IpAddress agent = new IpAddress("192.168.0.50");
// Construct target
UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
// Pdu class used for all requests
Pdu pdu = new Pdu(PduType.Get);
pdu.VbList.Add("1.3.6.1.2.1.1.1.0"); //sysDescr
pdu.VbList.Add("1.3.6.1.2.1.1.2.0"); //sysObjectID
pdu.VbList.Add("1.3.6.1.2.1.1.3.0"); //sysUpTime
pdu.VbList.Add("1.3.6.1.2.1.1.4.0"); //sysContact
pdu.VbList.Add("1.3.6.1.2.1.1.5.0"); //sysName
pdu.VbList.Add("1.3.6.1.2.1.3.1.1.2"); //这里想获取路由器的mac,但是不成功
// Make SNMP request
SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
if (result != null)
{
// ErrorStatus other then 0 is an error returned by
// the Agent - see SnmpConstants for error definitions
if (result.Pdu.ErrorStatus != 0)
{
// agent reported an error with the request
this.txtContent.Text += string.Format("Error in SNMP reply. Error {0} index {1} \r\n",
result.Pdu.ErrorStatus,
result.Pdu.ErrorIndex);
}
else
{
// Reply variables are returned in the same order as they were added
// to the VbList
this.txtContent.Text += string.Format("sysDescr({0}) ({1}): {2} \r\n",
result.Pdu.VbList[0].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[0].Value.Type),
result.Pdu.VbList[0].Value.ToString());
this.txtContent.Text += string.Format("sysObjectID({0}) ({1}): {2} \r\n",
result.Pdu.VbList[1].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[1].Value.Type),
result.Pdu.VbList[1].Value.ToString());
this.txtContent.Text += string.Format("sysUpTime({0}) ({1}): {2} \r\n",
result.Pdu.VbList[2].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[2].Value.Type),
result.Pdu.VbList[2].Value.ToString());
this.txtContent.Text += string.Format("sysContact({0}) ({1}): {2} \r\n",
result.Pdu.VbList[3].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[3].Value.Type),
result.Pdu.VbList[3].Value.ToString());
this.txtContent.Text += string.Format("sysName({0}) ({1}): {2} \r\n",
result.Pdu.VbList[4].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[4].Value.Type),
result.Pdu.VbList[4].Value.ToString());
}
}
else
{
this.txtContent.Text += string.Format("No response received from SNMP agent. \r\n");
}
target.Dispose();
}
请问如何获取路由器的mac啊?
pdu.VbList.Add("1.3.6.1.2.1.3.1.1.2"); //这里想获取路由器的mac,但是不成功