How do you take the IP address by opening the app

title says all
Title says nothing useful.

Which IP address?
- your local machine
- your public facing address as presented by your ISP
- your peer

Which app?
- something you've written
- something someone else has written

Two posts and both are leaner than lean on details to provide any substantial answers.

We have a "do the work for me" leech.
1.your public facing address as presented by your ISP;
2. something I've written;

sorry for not being specific
Still what you want to do is as clear as mud.

Have you tried to write any code to achieve your objectives?

Or do you expect us to do all the work for you?
Or even just typing the question into your favourite search engine.
https://duckduckgo.com/?q=how+to+find+my+public+ip+address
@salem c,

A very minor quibble, If'n I were to do a 'net search I'd add C++ to the query, so C/C++ relevant links pop up.

https://duckduckgo.com/?q=c%2B%2B+how+to+find+my+public+ip+address

I do agree with you a 'net search should be done before coming here asking questions should be Step Zero.
Probably something like: https://stackoverflow.com/a/65362666
The point being, you have to have something on the 'outside' reporting back what it sees as the IP address.
I use a home network of 3 desktop PCs interfacing with a ISP gateway, via a wifi router and several WIFI extenders, so the IP address obtained by the app in question has a lot of possible different answers:

what is the internal network IP addresses of the computer used to run the app, or any of my computers
what is the internal network IP address of the gateway
what are the internal network IP addresses of the router/extenders
what is the IP address used by the gateway to access the internet, seen by my ISP

do the router/extenders use dynamic or static IP addressing? Dynamic IP addressing really complicates how to get an IP address. For ease of maintenance I use static.

Another question that needs to be asked and answered:

is the IP address in IPv4 or IPv6?

To really add to the IP address mix I also have 2 networked printers and several tablet devices (iPad and Fire) that connect to the wireless WIFI on demand as well as two cell phones I can connect to WIFI when I want. Each of these devices have their own discrete IP address, available in IPv4 and IPv6 format, as well.

Lots of permutations to consider before even thinking about "how do I get an IP address when opening an app?"

@Ganado, my Gateway can report what IP address it uses to connect to my ISP, no need to "step outside" the network setup.

std::system("curl \"https://api.ipify.org\"");
mbozzi wrote:
std::system("curl \"https://api.ipify.org\"");


I'd prefer using libcurl directly, rather than forking a sub-process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <curl/curl.h>
 
int main(void)
{
  CURLcode res;
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://api.ipify.org/");
    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
    curl_easy_cleanup(curl);
  }
  return 0;
}


Source:
https://curl.se/libcurl/c/simple.html
Last edited on
Topic archived. No new replies allowed.