0

I'm writing a C# program to monitor all printers on the LAN via SNMP, using the open source #SNMP library (https://github.com/lextm/sharpsnmplib).
The method it uses for discovering SNMP devices is via UDP broadcast to the entire network (IPAddress.Broadcast = 255.255.255.255).
I have heard and read complaints from network administrators about broadcasting being bad practice that should be avoided by all means, because of poorly configured networks where it may flood the network to death.
So as an alternative method I tried the same library's Messenger.Get method in a loop, sending a unicast request to every ip in the local subnet range. There I also encountered a problem - using the non-async Get method in a loop takes too long. And the method's async sibling, GetAsync, hangs forever waiting for a response from all vacant ips, with no option to cancel the task or specify a timeout.
I'll be grateful to anyone who can point me in the right direction.

EDIT:
I've currently resorted to using Ping.SendPingAsync to ping in quick succession all ips in the subnet, and then sending an SNMP Get to those who responded to the ping. But I'm not sure if I can trust all printers to respond to pings. Could anyone please clarify this point as well?

Dan Z
  • 696
  • 8
  • 19
  • Does the GetAsync method not take a timeout value? Unfortunately I can't find documentation for that method. Fortunately Lex frequents this tag so I'm sure he'll be along shortly. – Lightness Races in Orbit Jan 25 '19 at 17:40
  • What you're doing now with multiple pings is far worse than broadcast. You should send a subnet-directed broadcast, i.e. not 255.255.255.255 but the actual broadcast address for your subnet. – user207421 Jan 27 '19 at 14:17
  • Like I wrote in the Background section, you are in a fully managed environment and all devices should be configured manually (as you are supposed to know their IP addresses in the network), https://docs.sharpsnmp.com/tutorials/device-discovery.html#background Why do you need UDP broadcasting then? – Lex Li May 09 '19 at 22:31
  • @LexLi I'm developing a utility to monitor printers that has to work out of the box, without having to require the network administrator to configure it manually by maintaining a list of all addresses to be scanned. At most he will have the option to define which subnets to scan. – Dan Z May 31 '19 at 09:47

0 Answers0