home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lookupi.zip / LOOKUP.PAS < prev   
Pascal/Delphi Source File  |  1996-11-18  |  884b  |  38 lines

  1. uses os2base, os2def, use32, sock, strstf, strings;
  2.  
  3. var
  4.   host: phostent;
  5.   buf: array[0..256] of char;
  6.   addr: string;
  7.   ip: ulong;
  8.  
  9. begin
  10.   if paramcount=0 then
  11.     begin
  12.       writeln('usage: lookup [ip/domain]');
  13.       halt(-1);
  14.     end;
  15.   addr:=truncstr(paramstr(1));
  16.   sock_init;
  17.   fillchar(host, sizeof(host), #0);
  18.   if not isip(addr) then host:=gethostbyname(strpcopy(buf, addr)) else
  19.     begin
  20.       ip:=inet_ston(addr);
  21.       host:=gethostbyaddr(@ip, sizeof(ulong), AF_INET);
  22.     end;
  23.  
  24.   if host=nil then
  25.     begin
  26.       writeln('unable to look up: '+addr);
  27.       halt(-1);
  28.     end;
  29.   if isip(addr) then
  30.     writeln('*** 0F'+addr+' 03resolved to: 0B', host^.h_name, '07')
  31.   else
  32.     begin
  33.       move(host^.h_addr_list^^, ip, host^.h_length);
  34.       writeln('*** 0F'+addr+' 03resolved to: 0B'+inet_ntos(ip), '07');
  35.     end;
  36. end.
  37.  
  38.