I recently came across this website called whatsmyrouterip.com. How does this website know both my private and public router IP address?

  • The method is described by and implemented in the code on the page.
    – symcbean
    Jul 13 '19 at 22:59
  • yeah but that only showed me how to get my router ip by myself, I am asking how does the website know
    – user212222
    Jul 13 '19 at 23:10

It looks like it tries to fetch the web page at each of a list of common router local IPs with JavaScript, deciding that it's found it when one responds. It uses jQuery's $.get(), but there are lots of ways to fetch one a web page from within another1. This assumes that the router has a web administration panel on port 80, but they usually do.

The relevant code is on and around line 2495 of the source code for the page (view-source:http://whatsmyrouterip.com/):

2463   var ips = [["", []], ["", []], ["", []], ...


2495   $.get('http://' + currentIp[0], function () {
2496     foundIp();
2497   });

1Well, getting the content may be tricky because of Same-Origin Policy, but a request that fails because of SOP and one that fails because the site doesn't exist look different so you can still tell if there's something there or not.