Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-22
3
Medium Priority
?
210 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
[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 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 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…
Suggested Courses

670 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