level 1
ProteinTZ
楼主
在网上找到了一些获取主机信息的代码:
protected void Button1_Click(object sender, EventArgs e)
{
string public1 = TextBox1.Text.Trim().ToString();
string IP = TextBox2.Text.Trim().ToString();
// SNMP community name
OctetString community = new OctetString(public1);
AgentParameters param = new AgentParameters(community);
param.Version = SnmpVersion.Ver1;
IpAddress agent = new IpAddress(IP);
// Construct target
UdpTarget target = new UdpTarget((IPAddress)agent,161, 2000, 2);
// 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
// Make SNMP request
SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
当在TextBox2获取的IP地址为IPV4地址时,可以获取到信息。而输入IPV6的地址会出现下面的情况:

2015年04月29日 07点04分
1
protected void Button1_Click(object sender, EventArgs e)
{
string public1 = TextBox1.Text.Trim().ToString();
string IP = TextBox2.Text.Trim().ToString();
// SNMP community name
OctetString community = new OctetString(public1);
AgentParameters param = new AgentParameters(community);
param.Version = SnmpVersion.Ver1;
IpAddress agent = new IpAddress(IP);
// Construct target
UdpTarget target = new UdpTarget((IPAddress)agent,161, 2000, 2);
// 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
// Make SNMP request
SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
当在TextBox2获取的IP地址为IPV4地址时,可以获取到信息。而输入IPV6的地址会出现下面的情况:
