pfinger.pp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. program pfinger;
  2. uses sockets,errors,inet;
  3. Var Addr : TInetSockAddr;
  4. S : Longint;
  5. Sin,Sout : Text;
  6. Line : string;
  7. hostname,username : string;
  8. host : THost;
  9. begin
  10. if paramcount<>1 then
  11. begin
  12. writeln ('Usage : pfinger username@hostname');
  13. end;
  14. HostName:=Paramstr(1);
  15. If pos('@',HostName)<>0 then
  16. begin
  17. username:=copy(HostName,1,pos('@',hostname)-1);
  18. hostname:=copy(HostName,pos('@',HostName)+1,255);
  19. end
  20. else
  21. username:='';
  22. Host.NameLookup(HostName);
  23. If Host.LastError<>0 then
  24. begin
  25. writeln ('Unknown host : ',host.name);
  26. halt(1);
  27. end;
  28. Addr.family:=AF_INET;
  29. { port 78 in network order }
  30. Addr.port:=ShortHostToNet(79);
  31. { localhost : 127.0.0.1 in network order }
  32. Addr.addr:=HostTonet(Longint(Host.IPAddress));
  33. S:=Socket(AF_INET,SOCK_STREAM,0);
  34. If Not Connect (S,ADDR,SIN,SOUT) Then
  35. begin
  36. Writeln ('Couldn''t connect to localhost');
  37. Writeln ('Socket error : ',strerror(SocketError));
  38. halt(1);
  39. end;
  40. rewrite (sout);
  41. reset(sin);
  42. writeln (sout,username);
  43. flush(sout);
  44. while not eof(sin) do
  45. begin
  46. readln (Sin,line);
  47. writeln (line);
  48. end;
  49. close (sin);
  50. close (sout);
  51. end.
  52. $Log$
  53. Revision 1.1 2002-01-29 17:54:53 peter
  54. * splitted to base and extra
  55. Revision 1.2 2000/07/13 11:33:26 michael
  56. + removed logs
  57. }