home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / scripts / finger < prev    next >
Text File  |  1997-06-10  |  1KB  |  43 lines

  1. #!perl -w
  2.  
  3. use Socket;
  4.  
  5. ($dest, $port) = @ARGV;
  6. $port = 'finger' unless $port;
  7.  
  8. ($who,$where) = $dest =~ m/(.*)@(.*)/ if defined $dest;
  9.  
  10. die "$0: victim\@host [port]\n" unless $where;
  11.  
  12. $sockaddr = 'S n a4 x8';
  13.  
  14. ($name, $aliases, $proto) = getprotobyname('tcp');
  15. ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/;
  16.  
  17. ($name,$aliases,$type,$len,$thataddr) = gethostbyname($where);
  18.  
  19. undef $type; undef $len;    # Keep -w happy
  20.  
  21. die "Unknown host $where" unless defined $name;
  22.  
  23. $that = pack($sockaddr, &AF_INET(), $port, $thataddr );
  24. socket(S, &PF_INET(), &SOCK_STREAM(), $proto) || die "socket: $!";
  25. # bind(S,$this) || die "$!";
  26.  
  27. connect(S,$that) || die "$!";
  28.  
  29. # Set socket to be command buffered.
  30. select(S); $| = 1; select(STDOUT);
  31.  
  32. # print "Going for $who\@$where\n";
  33. print "[$name]\n";
  34. print S "/w $who\r\n";
  35.  
  36.  
  37. # If you really want to know what local address we are bound to... 
  38. # $addr = getsockname( S );
  39. # @addr = unpack( 'xxxx CCCC', $addr );
  40. # print "we are " . join( '.', @addr ) . "\n";
  41.  
  42. print while defined( $_ = <S> );
  43.