testhosts.pp 775 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. {$mode objfpc}
  2. {$h+}
  3. program testhosts;
  4. uses sockets,netdb;
  5. Const
  6. {$ifdef unix}
  7. hosts = '/etc/hosts';
  8. {$else}
  9. {$ifdef win32}
  10. hosts = 'c:\windows\system32\drivers\etc\hosts';
  11. {$else}
  12. hosts = 'hosts'; { Fallback !! }
  13. {$endif}
  14. {$endif}
  15. var
  16. L,P : PHostListEntry;
  17. I : Integer;
  18. begin
  19. L:=ProcessHosts(Hosts);
  20. Try
  21. P:=L;
  22. I:=0;
  23. While (P<>Nil) do
  24. begin
  25. With P^ do
  26. begin
  27. Inc(I);
  28. Write(i:3,' Address : ',HostAddrToStr(NetToHost(P^.entry.addr)):15);
  29. Write(' hostname : ',P^.entry.Name);
  30. If (P^.entry.Aliases<>'') then
  31. Writeln(' Aliases : ',P^.entry.Aliases)
  32. else
  33. Writeln;
  34. P:=P^.next;
  35. end;
  36. end
  37. finally
  38. FreeHostslist(L);
  39. end;
  40. end.