Changes to external ip

Hello all
As you probably here all the time im quite new to all this and could really use some help in my project
I need my programing to:

  1. get external IP
  2. Wait for a while
  3. Get new external IP
  4. Compare the old and new to see if their are any changes

im really going nowhere any input would be appriciated
Thanks

  1. get external IP

Of what?

  1. Wait for a while

That's easy.

  1. Get new external IP

Of?

  1. Compare the old and new to see if their are any changes

And if they are?

Sorry, the external ip of the Ethernet board or rather the router/ the inetrnet connection it is using

Oh, if the external ip is different then it will hopefully send a get request to another server, i have actualy managed this bit and in my backwards thinking to start at the end and work my way back.
Thanks

I don't know if it's even possible to get the address of the outward facing IP of router that the Arduino is connected to. I asked that this topic be moved here to Networking, because it is more appropriate here. Perhaps someone else will be able to answer your question.

Put this php script to a server on Internet with know ip:

<?php
print ('<'.$_SERVER['REMOTE_ADDR'].'>');
?>

And use something like this script to read the ip from there: http://bildr.org/2011/06/arduino-ethernet-client/

Now you just need to compare the new and old ip values.

Is this what you are looking for?

llukkari:
Is this what you are looking for?

Yeah Thank you that helps a lot, I dont suppoze you would know how i could then compare the old from the new?
Thanks again

The easiest way, although probably not the most efficient, is to use the String class. What version of the Arduino environment are you using?

I dont suppoze you would know how i could then compare the old from the new?

How have you written the code to get the two values?

Well thats really the part i dont get, i can not get the external ip (thanks) so so far ive got:

//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte server[] = { 192,168,0,31 }; //ip Address of the server you will connect to

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String location = "/externalip.php/ HTTP/1.0";

// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
////////////////////////////////////////////////////////////////////////

EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

void setup(){
  Ethernet.begin(mac);
  Serial.begin(9600);
}

void loop(){
  String pageValue = connectAndRead(); //connect to the server and read the output

  Serial.println(pageValue); //print out the findings.

  delay(5000); //wait 5 seconds before connecting again
}

String connectAndRead(){
  //connect to the server

  Serial.println("connecting...");

  //port 80 is typical of a www page
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.print("GET ");
    client.println(location);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }else{
    return "connection failed";
  }

}

String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part 
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }

}

I setup a webserver localy on that ip for now which is printing the internal ip but shows alls working, so as of now i get a simple ip address.

So i think what i need to do is then save that numer as a string?
Then wait (thats the easy bit :slight_smile: )
Then change the name of the now old ip sting to "old"
Check again and call it "new"
Check old against new
If old is the same as new then...
If not start again
But i have no idea how to get the read data and save it as a string?

Thanks again for your time

Where did you get that crappy code?

There is no reason to be using the String class. There is, in particular, almost a crime in wrapping a global char array as a String just because you can't figure out what the correct return type for readPage() should be (hint: it's void).

Anyway, that code does something, and generates some serial output. The psychic we hired starts the 12th of never. If you need help before then, you'll tell us what that code actually does, and show the serial output.

You might start with some code like below.

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "checkip.dyndns.com"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.0"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Excellent code Changes to external ip
How do I send the ip found for a PHP page or email?
Or how do I access a page as http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&myip=ipaddress

You can use UPNP to get your external IP from your router.
This library can do it pretty easily.

Ok But I like to get my external ip (wan) to be able to access the Internet via arduino. In that case then I can not know the external IP.

Why would you need the External IP to access the internet?
I think you may need to read up on how TCP/IP works.

Your arduino will broadcast that it is on the network. It will look for a DHCP server. It will then be given all the details it needs to connect to the internet. (Internal IP address, DNS servers, Router Address) You NEVER need to know your external IP to access the internet. That will be handled by the router. You cannot even think of getting the external IP before you get all the details from your router. As soon as you have these if it supports UPNP you can just ask it for the external IP.

But how do I access the Internet Arduino if I do not know the external IP?

Your Router is given an IP address by your ISP. Then your router will give all the devices it is connected to an IP address. Your internal devices will be given the following over DHCP;
Internal IP address
Router IP address
DNS Server IP address
Subnet Mask

Your device is never given an external IP address. In order to get that you must either request it from your router OR connect to an external server which will then tell you the IP address that the request came from. Your entire network at home will have ONE external IP address.

few ways to get new ip from ISP;-

  1. disconnect from network from ISP, wait for x mount of time, then reconnect again and hope you get new ip.
  2. disconnect from network from ISP, change your own mac address, then reconnect again and hope you get new ip.
  3. use proxy server to change outbound ip.
  4. use reverse proxy server to change inbound ip.
  5. use VPN to change ip.
  6. use SSH Tunneling to change ip.
  7. use tor (www.torproject.org/) to make ip address fly ( ip address changed at every call)

The list should be much long, but I only list common one.