Solved

function to iterate through the IP addresses of the LAN network of current machine.

Posted on 2003-10-22
3
207 Views
Last Modified: 2010-04-05
The function should get the LAN Ip address from current machine, and iterate through all the IP addresses of the LAN network the current machine is part of.....
0
Comment
Question by:shaneholmes
3 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9600966
At the top of this page: http://www.torry.net/networks.htm there is a unit to get lists of computer names and IP addresses.

Geoff M.
0
 

Accepted Solution

by:
davidhusselmann earned 250 total points
ID: 9622042
Here is a function that returns a StringList with all the IPs of the local machine:

function LocalIPs: TStrings;
  type
    PPInAddr = ^PInAddr;
  var
    wsaData: TWSAData;
    HostInfo: PHostEnt;
    HostName: array[0..255] of char;
    Addr: PPInAddr;
  begin
    Result:= TStringList.Create;
    if WSAStartup($0102, wsaData) <> 0 then Exit;
    try
      if gethostname(HostName, SizeOf(HostName)) <> 0 then Exit;
      HostInfo:= gethostbyname(HostName);
      if HostInfo = nil then Exit;
      Addr:= Pointer(HostInfo^.h_addr_list);
      if (Addr = nil) or (Addr^ = nil) then Exit;
      Result.Add(inet_ntoa(Addr^^));
      Inc(Addr);
      while Addr^ <> nil do
      begin
        Result.Add(inet_ntoa(Addr^^));
        Inc(Addr);
      end;
    finally
      WSACleanup;
    end;
  end;

I didn't write this, I got it off the 'net somewhere, unfortunately I cannot remember where.  Thanks to whoever wrote it.

David
0
 
LVL 6

Expert Comment

by:swift99
ID: 9623915
Check out the libraries available at overbyte.delphicenter.com
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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