Solved

How to discover real IP address behind a router?

Posted on 2004-08-10
6
638 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now