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