Answer the question
In order to leave comments, you need to log in
How to determine your external IP in Delphi?
Good time of the day. I would like to know how to find out my external IP in Delphi? The IdIPWatch component does not suit me, as it allows you to find out only the local IP. Stupid solutions such as parsing (that's where the true FGM is!), I also ask you not to offer.
The search for a solution on the Web, as well as questions on other programming resources, did not bring the desired result. You are the last hope.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
If you mean the situation when your computer is behind NAT, then without the participation of any external service.
icanhazip.com
checkip.dyndns.org
Yandex
, etc.
you have two external networks, which external IP do you need?
always determined by a request to an external server, you don't have to parse )))
Actually, I am creating a server. And I need it to somehow determine the IP on which it sits. Do not enter manually each time?
Try!
uses
idHTTP;
function GetMyRealIP : String;
var
HTTP : TidHTTP;
text : String;
lc_pos : Integer;
begin
HTTP := TidHTTP.Create(nil);
try
text := HTTP.Get('http://whatismyip.com/');
finally
HTTP.Free;
end;
lc_pos := Pos('WhatIsMyIP.com</title>', text);
text := Copy(text, 1, lc_pos-1);
lc_pos := Pos('Your IP is', text);
text := Copy(text, lc_pos + 10, length(text) - lc_pos + 1);
Result := Trim(text);
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question