Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to discover real IP address behind a router?

Posted on 2004-08-10
6
648 Views
Last Modified: 2010-04-05
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
Comment
Question by:marcoandre
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11767906
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
 

Author Comment

by:marcoandre
ID: 11768711
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
 
LVL 4

Accepted Solution

by:
alikoank earned 125 total points
ID: 11769979
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:marcoandre
ID: 11774534
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
 

Author Comment

by:marcoandre
ID: 11777081
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
 
LVL 4

Expert Comment

by:alikoank
ID: 11777530
thanks for the grade :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question