• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

How to discover real IP address behind a router?

Hi Experts,

I want to discover the real IP address behind a router, using delphi. I also find this:

"
{
  If you are behind a router or proxy and want to get your real Internet-IP-Address then you
  need the help of a extern Internet Server. That extern Internet server have to tell you your
  real Ip-Address.  You can make this with a combination of PERL and DELPHI.
  The following PERL-SCRIPT you have to upload to an Webspace witch allows Perl/CGI-access:
}

--------------------------------------------------------
#!/usr/local/bin/perl

use CGI qw/:standard/;

print "Content-type: text/html\n\n";

print "BEGINIP".$ENV{REMOTE_ADDR}."ENDIP";
--------------------------------------------------------

{
   If the address of the Script is "http://www.my-server.de/cgi-bin/GiveMeMyIp.pl
  then the Delphi-Code to get your real IP is:
}

procedure TForm1.Button1Click(Sender: TObject);
var
  IPSTR, IP, HP: string;
  BeginIP, EndIP, i: integer;
begin
  Button1.Enabled := False;
  HP      := ‘http://www.my-server.de/cgi-bin/GiveMeMyIp.pl’;
    NMHTTP1.Get(HP);
  IPSTR   := (NMHTTP1.Body);
  BeginIP := Pos('BEGINIP', IPSTR) + Length('BEGINIP');
  EndIP   := Pos('ENDIP', IPSTR);
  IP      := '';
  for i := BeginIP to ENDip - 1 do
  begin
    IP := IP + IPstr[i];
  end;
  label1.Caption  := IP;
  Button1.Enabled := True;
end;

"

The question is: is there any way to do it differently, I mean, without using a server side (Perl) ?

Thanks!

[]s, Marco André
0
marcoandre
Asked:
marcoandre
  • 3
  • 2
1 Solution
 
LRHGuyCommented:
It may depend on the kind of router.

What I did at mine, a linksys, is grab the "status" page from the router, and extract what it reported was the IP address. I am also able to tell (since I have DSL) if the "outside world" connection is up, etc.

For most linksys:

  http://192.168.1.1/status.htm

will give the right page...
0
 
marcoandreAuthor Commented:
This solves the problem when you know the equipamment. In my case I want to do it inside a program, using Perl (Server side) or not.
0
 
alikoankCommented:
You can connect one of the proxy checking web pagesand parse their result page. There is a whole bunch of them out there.

http://www.stilllistener.addr.com/checkpoint1/index.shtml
http://www.richard.zonnet.nl/cgi-bin/nph-proxycheck

http://www.google.com/search?q=proxy+check&sourceid=opera&num=0&ie=utf-8&oe=utf-8
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
marcoandreAuthor Commented:
Hi alikoank,

Thanks for the answer. I have one more question: How can i parse (or get) these results? I mean, it have to be transparent to the user.

[]s, Marco André
0
 
marcoandreAuthor Commented:
Hi again,

With the help of Google Search, i found some interesting functions and adapted one:

function GetMyRealIP : String;
var
  HTTP : TIdHTTP;
  Memo : TMemo;
  Buff, P, FT: PChar;
  BuffLen : Word;
const
  WebAddress = 'http://www.whatismyip.com/';
  SearchString = 'Your ip is ';
  function GetIP : String;
  var
    StartPos : Word;
  begin
    Memo.SelStart  := P - Buff;
    Memo.SelLength := Length(SearchString);
    StartPos       := Memo.SelStart + Memo.SelLength;
    while ((Buff[StartPos] in ['0'..'9']) or (Buff[StartPos] = '.')) do
    begin
      Result := Result + Buff[StartPos];
      Inc(StartPos);
    end;
    FreeMem(FT, Length(SearchString) + 1);
    FreeMem(Buff, BuffLen);
  end;
begin
  Result := '';
  Memo   := TMemo.Create(Application.MainForm);
  HTTP   := TIdHTTP.Create(nil);
  Memo.Visible := False;
  Memo.Parent  := Application.MainForm;
  Memo.Clear;
  try
    try
      Memo.Text := HTTP.Get(WebAddress);
      if Memo.Text <> '' then
        begin
          Memo.SelStart := 0;
          GetMem(FT, Length(SearchString) + 1);
          StrPCopy(FT, SearchString);
          BuffLen := Memo.GetTextLen + 1;
          GetMem(Buff, BuffLen);
          Memo.GetTextBuf(Buff, BuffLen);
          P := Buff + Memo.SelStart + Memo.SelLength;
          P := StrPos(P, FT);
          if P <> nil then
            Result := GetIP;
        end;
    except
    end;
  finally
    FreeAndNil(Memo);
    FreeAndNil(HTTP);
  end;
end;
0
 
alikoankCommented:
thanks for the grade :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now