0

I need some code, preferably Java, to locate the IP address of a router on a SOHO-type network. As a bonus, I'd also like to get the make/model of the router along with the firmware version.

I see that HNAP will do the job, UPnP can sort of do it, and that they both depend on SSDP. The problem is that these things seem to be unreliable since they're able to be turned off and/or I'm not sure that all routers will even support this.

How can I definitively get the address? Does the answer lie in DHCP?

If I do get the address, is there any good way to likely get info on the router? HNAP seems like the right choice, but there seems to be very little info and no code out there about HNAP.

Does anyone have any code to do these things?

Sander Smith
  • 1,371
  • 4
  • 20
  • 30
  • There's some fairly horrible hacks [here](http://stackoverflow.com/q/11930/2071828). Not sure if there is a cross-platform way of doing this without depending on the config if the router. – Boris the Spider Mar 04 '14 at 10:01
  • If you need this to work everywhere, UPnP, HNAP and SNMP are all out of the question: Nothing guarantees that a SOHO router supports any of these. That also means you cannot get make and model reliably. You'll probably want to figure out how to get the IP of the default gateway in java. – Jussi Kukkonen Mar 04 '14 at 21:05
  • I'm realizing that I have 2 separate issues here. I'm surprised that getting the default gateway is such a hack in Java. I also realize that getting make/model is not guaranteed. However, all 4 routers I've tested out respond well to HNAP. Does anyone know how widely this is supported? – Sander Smith Mar 05 '14 at 03:19

1 Answers1

0

If your router supports SNMP, then that may be an approach. The system MIB will return basic info on the make/model etc. and there's likely an enterprise MIB that would give you a lot more. How do you find the router initially ? Possibly by interrogating your local routing via SNMP.

SNMP4J is a commonly used SNMP library for Java.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440