Forum > General

Get public IP adress

<< < (3/3)

MarkMLl:

--- Quote from: blastiko on August 15, 2022, 11:42:29 pm ---Under Linux, or in any case with curl installed:

--- End quote ---

Noting that that's your first post, welcome to the forum... but commenting to a mature thread tends to be frowned upon :-)

There's actually much better ways than using curl, based on looking in /proc... if using Linux, which OP didn't specifiy. But unfortunately this is a bit of a trick question, since even a computer with a single interface can have multiple IP addresses (and both v4 and v6 addresses) associated with it.

The right question is probably "if I connect to such-and-such a remote address, what local address will I be using".

MarkMLl

rvk:

--- Quote from: MarkMLl on August 16, 2022, 09:11:19 am ---But unfortunately this is a bit of a trick question, since even a computer with a single interface can have multiple IP addresses (and both v4 and v6 addresses) associated with it.

--- End quote ---
Not sure you understood the answer. It uses curl to query the site http://ifconfig.me.
That will give you just one external public IP address on Linux just like the other answers.

(Although I would rather suggest some http component already installed in FPC like TFPHTTPClient which also works under Linux.)


MarkMLl:

--- Quote from: rvk on August 16, 2022, 10:31:16 am ---Not sure you understood the answer. It uses curl to query the site http://ifconfig.me.
That will give you just one external public IP address on Linux just like the other answers.

--- End quote ---

Yes, but if the NIC is multi-homed using different subnets for different jobs?

OP might actually have been thinking about the address when he talked to a local database: how's querying an external website going to help with that? How's it going to help if his network routing uses different paths depending on the protocol, e.g. one path to an SMTP smarthost (which is the one he wants to know about) and another for everything else? How's it going to help if he goes via a NATing router for external connections but wants to know the host's /actual/ address?

MarkMLl

rvk:

--- Quote from: MarkMLl on August 16, 2022, 10:51:47 am ---OP might actually have been thinking about the address when he talked to a local database: how's querying an external website going to help with that?

--- End quote ---
OP already stated he can find the public IP with a browser

--- Quote from: Jake012345 on April 13, 2020, 08:51:42 pm ---(I can find it with browser but i want to use in a program)

--- End quote ---
and thanked for the first answer. So I guess the issue was already resolved and it was indeed the actual external IP address of his internet connection what he was after.

MarkMLl:

--- Quote from: rvk on August 16, 2022, 10:57:16 am ---and thanked for the first answer. So I guess the issue was already resolved and it was indeed the actual external IP address of his internet connection what he was after.

--- End quote ---

...so in this case the NATed one rather than the machine's apparent IP address. I've got a vague recollection of looking at that in the past for security reasons: I think there's an RFC (possibly just a draft) that discussed Carrier Grade NAT but I can't recall whether there's any standalone way of probing it other than using something akin to traceroute.

Looking back through some of my notes: I've certainly seen NATing mess up /apparent/ IP address allocation on e.g. IP going over a 4G connection, with the reported IP address being nothing like anything that appeared in a traceroute sequence. They've also reminded me that historically port 113 (ident) was significant, with either some sort of useful identifier reported or at the very least with an attempted external connection promptly refused rather than being tarpitted or allowed to time out.

MarkMLl

Navigation

[0] Message Index

[*] Previous page

Go to full version