line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################## |
2
|
|
|
|
|
|
|
# # |
3
|
|
|
|
|
|
|
# Net::Finger, a Perl implementation of a finger client. # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# By Dennis "FIMM" Taylor, # |
6
|
|
|
|
|
|
|
# # |
7
|
|
|
|
|
|
|
# This module may be used and distributed under the same terms # |
8
|
|
|
|
|
|
|
# as Perl itself. See your Perl distribution for details. # |
9
|
|
|
|
|
|
|
# # |
10
|
|
|
|
|
|
|
################################################################## |
11
|
|
|
|
|
|
|
# $Id$ |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Net::Finger; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
650
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
16
|
1
|
|
|
1
|
|
963
|
use Socket; |
|
1
|
|
|
|
|
7916
|
|
|
1
|
|
|
|
|
659
|
|
17
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
74
|
|
18
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT $error $debug); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
668
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
21
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
22
|
|
|
|
|
|
|
@EXPORT = qw( &finger ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$VERSION = '1.06'; |
25
|
|
|
|
|
|
|
$debug = 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# I know the if ($debug) crap gets in the way of the code a bit, but |
29
|
|
|
|
|
|
|
# it's a worthy sacrifice as far as I'm concerned. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub finger { |
32
|
0
|
|
|
0
|
0
|
|
my ($addr, $verbose) = @_; |
33
|
0
|
|
|
|
|
|
my ($host, $port, $request, @lines, $line); |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
unless (@_) { |
36
|
0
|
|
|
|
|
|
carp "Not enough arguments to Net::Finger::finger()"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Set the error indicator to something innocuous. |
40
|
0
|
|
|
|
|
|
$error = ""; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
|
$addr ||= ''; |
43
|
0
|
0
|
|
|
|
|
if (index( $addr, '@' ) >= 0) { |
44
|
0
|
|
|
|
|
|
my @tokens = split /\@/, $addr; |
45
|
0
|
|
|
|
|
|
$host = pop @tokens; |
46
|
0
|
|
|
|
|
|
$request = join '@', @tokens; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
$host = 'localhost'; |
50
|
0
|
|
|
|
|
|
$request = $addr; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if ($verbose) { |
54
|
0
|
|
|
|
|
|
$request = "/W $request"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($debug) { |
58
|
0
|
|
|
|
|
|
warn "Creating a new socket.\n"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
unless (socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'))) { |
62
|
0
|
|
|
|
|
|
$error = "Can\'t create a new socket: $!"; |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
select SOCK; $| = 1; select STDOUT; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
$port = ($host =~ s/:([0-9]*)$// && $1) ? $1 : |
68
|
|
|
|
|
|
|
(getservbyname('finger', 'tcp'))[2]; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ($debug) { |
71
|
0
|
|
|
|
|
|
warn "Connecting to $host, port $port.\n"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
unless (connect( SOCK, sockaddr_in($port, inet_aton($host)) )) |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
|
|
|
$error = "Can\'t connect to $host: $!"; |
77
|
0
|
|
|
|
|
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ($debug) { |
81
|
0
|
|
|
|
|
|
warn "Sending request: \"$request\"\n"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
print SOCK "$request\015\012"; |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($debug) { |
87
|
0
|
|
|
|
|
|
warn "Waiting for response.\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
while (defined( $line = )) { |
91
|
0
|
|
|
|
|
|
$line =~ s/\015?\012/\n/g; # thanks (again), Pudge! |
92
|
0
|
|
|
|
|
|
push @lines, $line; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if ($debug) { |
96
|
0
|
|
|
|
|
|
warn "Response received. Closing connection.\n"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
close SOCK; |
100
|
0
|
0
|
|
|
|
|
return( wantarray ? @lines : join('', @lines) ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |