List all IP address in use on a LAN

Hi Expert
How Can I list all the IP addres which are in use over my LAN ? I use some dynamic IPs (DHCP server) and some static IPs. I'd like to code something like "network neighbours" but listing Ip address near the PC name.
Thank you.
borgoAsked:
Who is Participating?
 
simonetConnect With a Mentor Commented:
Here's how I do it (and it works):

First of all, download  the sample for a Network enumerator application. You can find the sample application here:

http://www.delphifreestuff.com/examples/wnetexmp.zip

The sample app above will read all the machines (servers + wksta) on a LAN, plus all the shared/available resources on each machine. You can, if you want, make small adjustments on the application so it returns only machines. PLease let me know if you have troubles doing that.

Now, the second step is to get the IP for each machine found. For that you can use the function below, passing the name of the machine as the parameter:

uses WinSock;

function GetAddressByName(name : string) : string;
var
      wsdata      : TWSAData;
  he                  : PHostEnt;
  ss                  : pchar;
  ip                  : TInAddr;
begin
      WSAStartup(MakeWord(1, 1), wsdata);
  he := gethostbyname(pchar(name));
  if he<>nil then
  begin
        ip.S_addr := integer(pointer(he^. h_addr_list^)^);
     ss := inet_ntoa(ip);
     Result := string(ss);
  end;
  WSACleanup();
end;


That's all it takes.
Note: The function above may be a little slow depending on the network. On Win95 and WinNT networks it's a little slow.


Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
0
 
EpsylonCommented:
The easiest way I think is to ping a range IP addresses.

Use http://www.rtfm.be/fpiette/pinguk.htm to do that.

I don't know who to communicate with the DHCP server.

Epsylon.
0
 
borgoAuthor Commented:
Many thanx to all of you who have helped me.
Regards.
Borgo.

0
All Courses

From novice to tech pro — start learning today.