Pages: [1]   Go Down
Author Topic: ethernetshield ip address retriving  (Read 249 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Emsworth, UK
Offline Offline
Full Member
***
Karma: 8
Posts: 199
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

 


Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Emsworth, UK
Offline Offline
Full Member
***
Karma: 8
Posts: 199
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 138
Posts: 5833
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: