Go Down

Topic: ethernetshield ip address retriving (Read 313 times) previous topic - next topic

stoveitin

Hello,
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

tobyb121

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: 192.168.0.5 => Default Gateway: 192.168.0.1

stoveitin

Mine seem tottaly diffrent with no resemblance to eachother eg ardunio would be 192.168.0.0 and gateway/router 2.29.30.0 ... And the gateway changes all the time the ardunio ip never changes think its set by its mac address by the router

MattS-UK

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.





tobyb121

2.29.30.0 is not a valid default gateway, it will be in the ranges:
   10.0.0.0        -   10.255.255.255
   172.16.0.0      -   172.31.255.255
   192.168.0.0     -   192.168.255.255
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
Code: [Select]
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.

MattS-UK

2.29.30.0 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.
2.29.30.0 could be a valid the default route though
 
Try visiting http://www.whatsmyip.org
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.


tobyb121

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

SurferTim

If you need the default gateway for the ethernet shield, this will get it.
Code: [Select]
Serial.print(F("Default gateway = "));
IPAddress newGateway = Ethernet.gatewayIP();
Serial.println(newGateway);


Go Up