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.
source share