I currently query an external server for my external IP address, but I should really query my own router. It would limit the traffic to the LAN, and the router certainly knows what the address is. Does anybody know if there's a concise way of querying the router (other than screen scraping the status page). Thanks!
-
Depends on what you are trying to do with it. Are you looking for a powershell script, vbscript script, bash script, python script, ect... Your platform and how you plan on using the info will greatly affect answers.– Scott ChamberlainDec 29, 2013 at 21:31
-
Are you comfortable using SNMP?– BandramiDec 29, 2013 at 21:58
-
2If the router itself is behind NAT, it may not know its own external IP address.– David SchwartzDec 29, 2013 at 22:36
-
@Bandrami Yes, SNMP would have been the "correct" way, but more complex than my eventual solution.– erictNov 4, 2015 at 0:09
3 Answers
in console, run "nvram get wan_ipaddr"
-
-
@erict It looks pretty concide to me. Please make your requirements clearer. Oct 8, 2015 at 10:45
-
@David As the title indicates, I want to do this programmatically. My requirements are that I have a server that wants to know the external internet address, even though it is NATed through a DD-WRT router. I was querying an external server like whatismyip.com, but wanted a solution that doesn't depend on external sources. I eventually found that I can query the DD-WRT router's page called Status_Internet.live.asp which returns a bunch of info, including the WAN IP.– erictNov 4, 2015 at 0:07
I found an acceptable solution. Request page
http://router_ip/Status_Internet.live.asp
from your dd_wrt router (it needs authentication). This output is not dependent on the GUI style, since it is only the auto-refresh data. It's very easy to extract the IP address from the returned data.
Try to install php, if it isn't already installed.
Make a floder.
Make a php internal webserver -- the one built in.
Let it return the ouput from
ifconfig |grep "inet addr" |cut -d: -f2 |cut -d" " -f1
It will return all the ip addresses it has (internal, external and loopback). You can then poll this instead of the external server.
-
1wouldn't work -- need the external IP on the other side of a router (specifically a DD-WRT router). Your suggestion would return the local IP addresses– erictDec 30, 2013 at 0:44