Solved

How to discover real IP address behind a router?

Posted on 2004-08-10
6
644 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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