简体   繁体   English

使用广播snmp请求进行网络发现

[英]Network discovery using broadcast snmp requests

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/ 我可以使用以下链接中提到的net-snmp做到吗-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. 我应该在snmp_api中启用任何广播标志吗? 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 您能否在这个简单的应用程序的上下文中解释我-http: //www.net-snmp.org/wiki/index.php/TUT:Simple_Application

I'm new to SNMP. 我是SNMP的新手。 Any help is much appreciated. 任何帮助深表感谢。

PS: I use net-snmp 5.7.2.1 PS:我使用net-snmp 5.7.2.1

You need to understand that SNMP is not a protocol with device discovery defined, 您需要了解SNMP不是定义了设备发现的协议,

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

Your broadcast message might receive a response only if that device happens to use the community name you use (for v1 and v2c). 仅当该设备恰好使用您使用的社区名称(对于v1和v2c)时,您的广播消息才可能收到响应。

Don't rely on broadcasting, as for security concerns many devices use very special community names, and they won't respond. 不要依赖广播,因为出于安全考虑,许多设备使用非常特殊的社区名称,因此它们不会响应。

// to identify the printer if sysservice value is 72 printer else not //如果sysservice值为72,则标识打印机,否则

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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM