procedure TForm1.Button6Click(Sender: TObject);
var
MyStream:TMemoryStream;
t_ns:tNetBiosNS;
i:byte;
count,ipcount:integer;
netip:string;
begin
with t_ns do
begin
tID:=$0000;
Flags:=$1000;
Questions:=$0100;
AnswerRRs:=$0000;
AuthorityRRs:=$0000;
AdditionalRRs:=$0000;
Name[1]:=$20;
Name[2]:=$43;
Name[3]:=$4b;
for i:=4 to 33 do
Name[i]:=$41;
Name[34]:=$00;
tType:=$2100;
tClass:=$0100;
end;
nmudp1.LocalPort:=3000;//UDP绑定的本地主机的端口
nmudp1.RemotePort:=137;// NetBIOS-NS ,137端口
count:=0;
ipcount:=1;
while count<44 do
begin
netip:='192.168.1.'+inttostr(ipcount);
nmudp1.RemoteHost:=netip;
MyStream:=TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream); //为什么要等到最后一个有返回信息时候才触发事件
finally
MyStream.Free;
end;
count:=count+1;
ipcount:=ipcount+1;
end;
end;
var
MyStream:TMemoryStream;
t_ns:tNetBiosNS;
i:byte;
count,ipcount:integer;
netip:string;
begin
with t_ns do
begin
tID:=$0000;
Flags:=$1000;
Questions:=$0100;
AnswerRRs:=$0000;
AuthorityRRs:=$0000;
AdditionalRRs:=$0000;
Name[1]:=$20;
Name[2]:=$43;
Name[3]:=$4b;
for i:=4 to 33 do
Name[i]:=$41;
Name[34]:=$00;
tType:=$2100;
tClass:=$0100;
end;
nmudp1.LocalPort:=3000;//UDP绑定的本地主机的端口
nmudp1.RemotePort:=137;// NetBIOS-NS ,137端口
count:=0;
ipcount:=1;
while count<44 do
begin
netip:='192.168.1.'+inttostr(ipcount);
nmudp1.RemoteHost:=netip;
MyStream:=TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream); //为什么要等到最后一个有返回信息时候才触发事件
finally
MyStream.Free;
end;
count:=count+1;
ipcount:=ipcount+1;
end;
end;
MyStream:=TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream); //为什么要等到最后一个有返回信息时候才触发事件
//添加一下两句,用来发送消息和等待处理
Application.ProcessMessages;
Sleep(100);
finally
MyStream.Free;
end;
count:=count+1;