ethernetshield ip address retriving

I am currently writing a program using the mega with a ethernetshield and need to know when my gateway ip address changes and what too.

So is there a easy way to get the address of your gateway your connected through eg I'm going through a livebox router .

I know you can get the ip of the ardunio itsself but struggling to find a easy way to get the gateway ip.

Cheers tom

The default gateway will be the IP address of your router. For 99% of cases it will be the same as the IP address of the Arduino (if you've configured it correctly) with the last byte changed to a 1:
e.g. Arduino IP: => Default Gateway:

I think you may be talking about different things.

A router always has two addresses. One, the inside address, is valid on the local network. The other, the outside address, is valid on the network the router is forwarding packets to.

It sounds like the outside address is the one you are after. The public IP address assigned to your router by your ISP. Finding your public IP is not entirely straightforward, thanks to the IP sharing protocol NAT.

If your router supports it, Dynamic DNS is about the easiest way to keep track of your public IP address. Have a look within your router admin pages. is not a valid default gateway, it will be in the ranges: - - -
As these are the only ranges that are reserved for private/local networks. On your PC, when connected to the network bring up a command prompt and type in

ipconfig /all

This will give you information on all of the network cards active in your computer. Find your connection in the list and read off the Default Gateway address from there. is a public address assigned to Orange / Wanadoo. The Livebox is a router provided by Orange.

The .0 doesn't look right, unless Orange are doing something a little creative. could be a valid the default route though

Try visiting
To check what your outside address really is.

I feel I need to now ask, why do you need this address?
It might help to fathom which address you should be looking at.

The external IP shouldn't matter to the Arduino, you need the default gateway so that the Arduino knows where to send external requests.

If you need the default gateway for the ethernet shield, this will get it.

Serial.print(F("Default gateway = "));
IPAddress newGateway = Ethernet.gatewayIP();