2

I looked for any SNMP scanner tool for Linux that can SNMP query an IP range for multiple OIDs and return results (if found), but didn't find anything.

I have SNMP installed on Ubuntu, is it possible with snmpget command query the network range for multiple OIDs and retrieve MIB values? Is it possible do this from terminal as single command?

For example, snmpget network range 10.40.70.1/24 for 4 OIDs (OID1, OID2, OID3, OID4).

11
  • If the OIDs are in the same tree, you might use snmpwalk, otherwise snmpbulkget. But afaik network ranges are not supported by snmp tools, as they only allow the definition of one agent.
    – ridgy
    Commented Jan 31, 2017 at 12:04
  • Yes, OIDs are in the same tree. But is it possible scan hosts from network range one by one, not multiple hosts at once? (not multi-threaded parallel scanning).
    – Lexx Luxx
    Commented Jan 31, 2017 at 13:53
  • Well, in bash you can do for (( i=254; $i; i=$i-1 )) do host=10.40.70.$i; if (ping -q -c 1 $host >/dev/null); then snmpget -v2c -c public $host OID1 OID2 OID3 OID4; fi; done. But that might bring you trouble with your network administrator...
    – ridgy
    Commented Jan 31, 2017 at 14:14
  • 1
    man snmpgetsays so... maybe remove the >/dev/nullto see what's going on. Or instead of testing with pingyou could immediately call snmpget: for (( i=254; $i; i=$i-1 )) do host=10.40.70.$i; snmpget -v 2c -c public $host OID1 OID2 OID3 OID4; done. And of course change the options of snmpget to match your needs (-v 2c and -c public is just an example)
    – ridgy
    Commented Jan 31, 2017 at 19:04
  • 1
    You could add -t 0.5 -r 1 to the snmpget options; this will return faster with timeout (but you might not catch all hosts this way). And be aware that the line suggested implies that all hosts have same snmp version and community. To keep a script from exiting at the end you may use read: read -p 'press enter to continue...' answer
    – ridgy
    Commented Feb 1, 2017 at 10:43

1 Answer 1

1

In bash, you can do something like:

for host in 10.40.70.{1..254}; do
  snmpget -v2c -c public $host OID1 OID2 OID3 OID4
done

You can use {a..z} or {a,b,c} ranges in place of multiple digits.

3
  • Can you clarify about specifying ranges for private networks Class A?
    – Lexx Luxx
    Commented Jan 24, 2023 at 16:44
  • 1
    It's possible to do something like for ip in 10.{0..255}.{0..255}.{0..255}; do snmpget ....; done, but it will take a long time to scan 16 million IP addresses, particularly if most of them time out.
    – mwfearnley
    Commented Jan 26, 2023 at 11:24
  • sure, no need to scan 16 million IP addresses, when possible to use target range 10.40.70.{1..254};
    – Lexx Luxx
    Commented Jan 29, 2023 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .