Solved

How to discover real IP address behind a router?

Posted on 2004-08-10
6
653 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
[X]
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
  • 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
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!

 

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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