home *** CD-ROM | disk | FTP | other *** search
- program Scan_UDP_NBNS137;
- {
- checks for presents of NetBios Name Service on UDP port 137
- and resolves hostnames and browsemasters if possible
- }
-
- procedure SetDetected(hname,responce:string);
- begin
- if length(hname)<>0 then NVSCAN_HOSTNAME:=LowerCase(hname);
- NVSCAN_RESPONCE:=responce;
- NVSCAN_DETECTED:=true;
- end;
-
- var s,name,hostname,bmlist:string;
- n,i,j,tip,svc:integer;
- begin
- s:=chr(1+random(142))+chr(1+random(142));
- s:=s+#0#0#0#1#0#0#0#0#0#0' CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'#0#0#33#0#1;
- send(s);
- s:=recv;
- if length(s)>56 then
- begin
- n:=ord(s[57]);
- if (n*18+57)<=length(s) then
- begin
- for i:=0 to n-1 do
- begin
- j:=58+i*18;
- name:=Trim(copy(s,j,15));
- svc:=ord(s[j+15]);
- tip:=ord(s[j+16]);
- if (tip and $80)=0 then
- begin
- case svc of
- 0:hostname:=name;
- $20:hostname:=name;
- $1d:bmlist:=bmlist+(name+', ');
- end;
- end;
- end;
- if length(bmlist)>2 then
- begin
- setlength(bmlist,length(bmlist)-2);
- bmlist:='Master browser: '+bmlist;
- end else setlength(bmlist,0);
- SetDetected(hostname,bmlist);
- end else if length(s)>0 then SetDetected('','Invalid reply');
- end else if length(s)>0 then SetDetected('','Too short reply');
- end.
-