Solved

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

Posted on 2003-10-22
3
205 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

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

Suggested Solutions

Title # Comments Views Activity
how to draw animated progressbar in Tvirtualstringtree 5 117
Mobile Keyboard covers the display of the TMemo 3 78
Run video youtube webbrowse 10 57
DBGrid or StringGrid ? 6 70
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

15 Experts available now in Live!

Get 1:1 Help Now