Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking Status of Router/Switch  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So a guy I work with has been evaluating network montoring applications so that we might be notified of system failures ASAP. Fine and dandy. Well, with the way my brain works I thought, ooh, cool, I'd like to see how well Java might be able to do some stuff like that. If there is anywhere in Java I am lacking, it is sockets.

Java doesn't support Ping and our network does not allow UDP. I would rather not do JNI to something that supports Ping, nor do I want to run an external process. So I am looking for ideas of how to, in essence, "ping" a router or switch using Java and making sure I have a response. I've already been able to connect to a router, login, and issue a few commands using Sockets. Not sure if I want to go to the extent/time of logging into the router each time just to make sure it's on. Any ideas are greatly appreciated.
[ August 05, 2005: Message edited by: Gregg Bolinger ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't necessarily the most robust solution, but as long as you're not selling it as a commercial product...

Try to open a socket to a port that isn't open on the router. If the router is up and isn't blackholing stray connections, then you'll get a ConnectException with a message like "Connection refused". If the router is down, you should get a NoRouteToHostException (or something like that) with a message about "No route to host".

If this doesn't work because the router just drops connections to random ports, then you could open a socket to the login port, and just close the connection if it works. If it doesn't work, the router is down.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, JMX kind of supports SNMP (simple network monitoring protocol) so depending on the products you're using, you might be able to make use of that. SNMP is, however, an overkill if you're only concerned about a couple in-house systems. I'd probably just open a TCP socket connection, verify that it's open, and close it. Or log in and out--shouldn't be a problem if you do it only once in a couple of minutes.

(PS. you could always do "ping" with Runtime.exec() and parse the output ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!