How can I identify Windows hosts on a subnet with Delphi?

I have an administrative application that I would like to "discover" Windows hosts on the same or user-specified subnet. What do you think is the best way to quickly find out if a range of hosts is available using Delphi?

I considered pinging hosts (possibly using WMI and Delphi ), but I believe that there may be a more reliable way. I am concerned that clients may be configured to not respond to ping requests. Using nbtscan , I can very quickly get a list of Windows hosts on my subnet:

nbtscan 192.168.1.0/24 

I would like to be able to replicate this functionality, but I'm not sure where to start. I am currently using the ICS component created by FranΓ§ois Piette for Delphi 2010.

I welcome any suggestions.

+4
source share
2 answers

After some digging, I found this project on Sourceforge that demonstrates how to search for NetBios on a single host using Indy components. I tested, and this project works well with Delphi 2010. This could, of course, be changed to run NetBios requests at a number of addresses.

Nblookup

 unit uNbLookup; interface (************************************************************ 06-02-2007 - Petricca Antonio ( antonio.petricca@gmail.com ) Free for any purpose... Thanks to: Jim Halfpenny http://directory.fsf.org/security/misc/nbtstat.pl.html ************************************************************) uses IdGlobal, IdUDPClient, SysUtils, Windows; function NetBiosLookup(AAddress: PChar; AHostName: PChar; ATimeOut: Integer): BOOL; stdcall; implementation const NB_REQUEST = #$A2#$48#$00#$00#$00#$01#$00#$00 + #$00#$00#$00#$00#$20#$43#$4b#$41 + #$41#$41#$41#$41#$41#$41#$41#$41 + #$41#$41#$41#$41#$41#$41#$41#$41 + #$41#$41#$41#$41#$41#$41#$41#$41 + #$41#$41#$41#$41#$41#$00#$00#$21 + #$00#$01; NB_PORT = 137; NB_BUFSIZE = 8192; function NetBiosLookup(AAddress: PChar; AHostName: PChar; ATimeOut: Integer): BOOL; stdcall; var Buffer : TIdBytes; I : Integer; RepName : String; UDPClient : TIdUDPClient; begin RepName := ''; Result := False; UDPClient := nil; if not Assigned(AHostName) then Exit; try UDPClient := TIdUDPClient.Create(nil); with UDPClient do begin Host := Trim(AAddress); Port := NB_PORT; Send(NB_REQUEST); end; SetLength(Buffer, NB_BUFSIZE); if (0 < UDPClient.ReceiveBuffer(Buffer, ATimeOut)) then begin for I := 1 to 15 do RepName := RepName + Chr(Buffer[56 + I]); RepName := Trim(RepName); StrPCopy(AHostName, RepName); Result := True; end; except Result := False; end; if Assigned(UDPClient) then FreeAndNil(UDPClient); end; end. 
+1
source

Why do not you use a scanner for this, for example nmap .

And if for some reason you cannot, you can read about how they do it.

Note Remote OS Discovery and TCP / IP Fingerprint Methods Supported by Nmap Hope this helps.

+2
source

Source: https://habr.com/ru/post/1346559/


All Articles