-->

Network discovery using broadcast snmp requests

2019-09-09 15:53发布

问题:

I want to discover the printers in my sub-net. Can I do that using net-snmp as mentioned in this following link- https://sourceforge.net/p/net-snmp/bugs/2336/

But it doesn't seem to work? Should I enable any flag for broadcast in snmp_api to do that. Also how will I go about handling the responses? Could you explain me in context of this simple application- http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application

I'm new to SNMP. Any help is much appreciated.

PS: I use net-snmp 5.7.2.1

回答1:

You need to understand that SNMP is not a protocol with device discovery defined,

https://sharpsnmplib.codeplex.com/wikipage?title=SNMP%20Device%20Discovery&referringTitle=Documentation

Your broadcast message might receive a response only if that device happens to use the community name you use (for v1 and v2c).

Don't rely on broadcasting, as for security concerns many devices use very special community names, and they won't respond.



回答2:

// to identify the printer if sysservice value is 72 printer else not

public void getDiscover(String oid_index){
    tempOID = "1.3.6.1.2.1.1.7";

    try{
    while(tempOID.equalsIgnoreCase("1.3.6.1.2.1.1.7")){
        //System.out.println("tttt");
    pair  = (SNMPSequence)(new SNMPRequest(community, tempOID, **"IP"**, version)).getRequest(2).getSNMPObjectAt(0);
    //mpValue = pair.getSNMPObjectAt(1);
    oid_index = pair.getSNMPObjectAt(0).toString();
  //tempOID = pair.getSNMPObjectAt(0).toString().substring(0,10);
    index.addElement(snmpValue);
    System.out.println(snmpValue.toString());// sysservice value
    }