Chat freely about anything...

User avatar
By danbicks
#46004 Guys,

Does anyone know a website that simply returns remote internet IP without returning loads of blurb?

Simple enough to do a HTTP request but don't want loads of blurb to filter through. Any good sites for this purpose?

Cheers

Dans
User avatar
By danbicks
#46173 Guys, this may come in handy, Martin recommended a site to me to grab remote internet ISP IP.
This is very useful, my need is to send a request via MQTT, a given node reports back with the ISP IP and then I connect to it and control it via telnet. Very handy, thanks Martin for the URL.

Here is a simple routine I have knocked up to fill this need, you can specify if the result is Json formatted or normal text. I am sure are Guru's have a better way, but works for me :)

Dans

Code: Select allString GetRemoteIP(bool varJson)
{
 
    const uint16_t port = 80;
    const char * host = "api.ipify.org"; // ip or dns 
    String line = "";
    Serial.print("connecting to ");
    Serial.println(host);
    WiFiClient rclient;

    if (!rclient.connect(host, port)) {
        Serial.println("connection failed");
       }
       else
       {
        Serial.println("Connected to host");
       }

  String vHTML = "";
  vHTML = "GET ";
  if (!varJson){
     vHTML += "/?";
     }else{
     vHTML += "/?format=json";
     }
  vHTML += " HTTP/1.1\r\nHost:";
  vHTML += "api.ipify.org";
  vHTML += "\r\n\r\n";

    rclient.print(vHTML);
        for (int i=0; i <= 10; i++){
            delay(10); // loop gives 100ms buffer fill time
            yield();
            }
           
    while(rclient.available())
           {
           line = rclient.readStringUntil('\r');
           }
           
    Serial.println("closing connection");
    rclient.stop();
    return line;
   
}