Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find Router IP Address/Real IP Address behind Router

Posted on 2003-11-15
3
Medium Priority
?
2,043 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
[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 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 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