Network discovery using broadcast snmp requests

半城伤御伤魂 提交于 2019-12-25 07:04:42

问题


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
    }


来源:https://stackoverflow.com/questions/25894554/network-discovery-using-broadcast-snmp-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!