0

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

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
user3651245
  • 5
  • 1
  • 4
  • Please clarify the matter of "what did you try". Also, what is the output you receive, when you try? You could try making the same request using the command-line tool `snmpget`, to rule out programming error on your part. – Jolta Sep 18 '14 at 12:15
  • I tried command-line too. I get a timeout when I send a 'snmpget' request to a broadcast address. – user3651245 Sep 18 '14 at 23:14
  • Try putting your PC on the same subnetwork as the printers. Does it start working? Then you have a routing problem. Ask your local network administrator what the restrictions are on broadcast packets in your network. Most routers will discard broadcast packets from outside, for security reasons. Your admin may be able to set up an exception for your management station. – Jolta Sep 19 '14 at 12:44
  • I guess this is working. So now I'm trying to ping the broadcast address of the subnet in which my computer is. I don't get 'Timeout'. Although I get a error for 'snmpget' and no response for 'snmpwalk'.I get a response for 'snmpgetnext' which keeps changing when I'm executing the command again and again. I'm assuming it is walking through the responses it got from all the printers in the subnet?!?! What is the right way of getting all the responses from all the printers in one file? – user3651245 Sep 20 '14 at 01:14
  • You should not expect that snmpwalk or snmp-get-next should ever be feasible over broadcast, since each responding host will have their own separate ordering of OIDs. The semantics are not defined (as Lex Li writes in his answer). You _should_ be able to get responses to a simple get request, but like Lex writes, you'd better be sure all your printers use the same community string. – Jolta Sep 22 '14 at 07:55

2 Answers2

3

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.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

// 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
    }
JSN
  • 1