Solved

Find Router IP Address/Real IP Address behind Router

Posted on 2003-11-15
3
1,987 Views
Last Modified: 2012-08-14
I need to be able to determine the Real DHCP IP address of the Router in a Network. There are a number of exmples of how to obtain the IP address of a given workstation, but if you are behind a Router/Firewall how do you determine the IP address that the rest of the world see you at. The Router has a web page that displays that IP address, but how do you get that IP address through a Delphi Program?
0
Comment
Question by:piano082497
3 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 250 total points
ID: 9757404
piano,

You are on the right track. There are only 2 possibilities:

1. call a website on the web that displays your wan ip and parse the ip from the webpage (e.g. http://www.whatismyip.net)
2. connect to your router through http, telnet, ... and try to get it directly from the hardware

To your question, try this code below:

{ uses WinInet }

function LoadFromURL(URL: String): String;
var
  hSession, hURL: hInternet;
  Buffer: array[0..1023] of Byte;
  BufferLength: DWord;
  Stream: TStringStream;
begin
  stream := TStringStream.Create('');
  Result := '';
  if (Pos('http://', LowerCase(url)) = 0) then URL := 'http://' + URL;
  hSession := InternetOpen('My_App;)', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    hURL := InternetOpenURL(hSession, PChar(URL), nil, 0, INTERNET_FLAG_RELOAD, 0);
    try
      repeat
        InternetReadFile(hURL, @Buffer, 1024, BufferLength);
        Stream.WriteBuffer(Buffer, BufferLength);
        Application.ProcessMessages;
      until (BufferLength = 0);
      Result := Stream.DataString;
     finally
       InternetCloseHandle(hURL)
     end;
  finally
    InternetCloseHandle(hSession);
    Stream.free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := LoadFromURL('router-ip/site.html');
end;

Now, you only have to parse your wan ip from the returned html code. This should be quite simple!

Markus
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

23 Experts available now in Live!

Get 1:1 Help Now