Board index » delphi » Enumerate computer IPs in local network

Enumerate computer IPs in local network

Hi guys

I know how to enumerate computer names in network (below is function to do
that), but my problem is, i need their IP addresses
How to do that? I tried getHostbyName which seemed as reasonable function,
but i am connected to internet through Dial up connection so whenever i call
that function Dial-up connection dialog always pops up. Is there any other
way to get IPs in my LAN?

procedure EnumNetResources(List: TStrings);

  procedure EnumFunc(NetResource: PNetResource);
  var
    Enum: THandle;
    HEnt : THostEnt;
    Count, BufferSize: DWORD;
    Buffer: array[0..16384 div SizeOf(TNetResource)] of TNetResource;
    i: Integer;
  begin
    if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NetResource,
Enum) = NO_ERROR then
    try
      Count := $FFFFFFFF;
      BufferSize := SizeOf(Buffer);
      while WNetEnumResource(Enum, Count, @Buffer, BufferSize) = NO_ERROR do
        for i := 0 to Count - 1 do
        begin
          if Buffer[i].dwDisplayType = RESOURCEDISPLAYTYPE_SERVER then
            begin
             List.Add(Buffer[i].lpRemoteName);
            end;
          if (Buffer[i].dwUsage and RESOURCEUSAGE_CONTAINER) > 0 then
            EnumFunc(@Buffer[i])
        end;
    finally
      WNetCloseEnum(Enum);
    end;
  end;

begin
  EnumFunc(nil);
end;

 

Re:Enumerate computer IPs in local network


Use the GetHostByName function from the WinSock unit to retreive the IP
address(es) for each server.

"Vlado" <intel...@siol.net> schreef in bericht
news:%fQk6.1690$Q8.76134@news.siol.net...

Quote
> Hi guys

> I know how to enumerate computer names in network (below is function to do
> that), but my problem is, i need their IP addresses
> How to do that? I tried getHostbyName which seemed as reasonable function,
> but i am connected to internet through Dial up connection so whenever i
call
> that function Dial-up connection dialog always pops up. Is there any other
> way to get IPs in my LAN?

> procedure EnumNetResources(List: TStrings);

>   procedure EnumFunc(NetResource: PNetResource);
>   var
>     Enum: THandle;
>     HEnt : THostEnt;
>     Count, BufferSize: DWORD;
>     Buffer: array[0..16384 div SizeOf(TNetResource)] of TNetResource;
>     i: Integer;
>   begin
>     if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NetResource,
> Enum) = NO_ERROR then
>     try
>       Count := $FFFFFFFF;
>       BufferSize := SizeOf(Buffer);
>       while WNetEnumResource(Enum, Count, @Buffer, BufferSize) = NO_ERROR
do
>         for i := 0 to Count - 1 do
>         begin
>           if Buffer[i].dwDisplayType = RESOURCEDISPLAYTYPE_SERVER then
>             begin
>              List.Add(Buffer[i].lpRemoteName);
>             end;
>           if (Buffer[i].dwUsage and RESOURCEUSAGE_CONTAINER) > 0 then
>             EnumFunc(@Buffer[i])
>         end;
>     finally
>       WNetCloseEnum(Enum);
>     end;
>   end;

> begin
>   EnumFunc(nil);
> end;

Other Threads