Solved

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

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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