D
D
docbrain2016-03-28 14:36:40
Delphi
docbrain, 2016-03-28 14:36:40

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

4 answer(s)
A
Andrew, 2016-03-28
@OLS

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.

D
Dimonchik, 2016-03-28
@dimonchik2013

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 )))

D
Docbrain, 2016-03-28
@Docbrain

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?

C
Chvalov, 2016-04-02
@Chvalov

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 question

Ask a Question

731 491 924 answers to any question