File: pqotd

package info (click to toggle)
ptknettools 0.2.3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 96 kB
  • ctags: 19
  • sloc: perl: 649; makefile: 34
file content (110 lines) | stat: -rwxr-xr-x 2,021 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl
# pqotd v0.1
# Copyright Alan Ford <alan@whirlnet.co.uk> 07/05/99
# Distributed with no warranty under the GNU Public License
#
# pqotd (Perl Quote of the Day) will connect to the
# specified host on the specified tcp port, receive the data
# given, and display it.
#
# The default port is 17, for Quote of the Day (qotd), but
# other protocols it could be used for include systat (11)
# and daytime (13).

require 5.002;
use IO::Socket;
use Socket;
use English;
sub help ;
sub version ;

my $version = "0.1";

if (not $ARGV[0]) {
   help;
}

if ($ARGV[0] =~ /help$/) {
   help;
}

if ($ARGV[0] eq "-?") {
   help;
}

if ($ARGV[0] eq "-h") {
   help;
}

if ($ARGV[0] eq "--version") {
   version;
}

my $verbose = 0;

if ($ARGV[2] eq "--verbose") {
   $verbose = 1;
}

if ($ARGV[2] eq "-v") {
   $verbose = 1;
}

my $host = $ARGV[0];
my $port = $ARGV[1];
$port = "17" unless $port;

if ($verbose == 1) {
    print "[$host:$port]\n";
}

my $remote = IO::Socket::INET->new(
    	       Proto    => "tcp",
    	       PeerAddr => $host,
    	       PeerPort => $port,
      	      ); 

unless ($remote) { 
    print "Cannot connect to $host\n";
    next;
}

$remote->autoflush(1);

while ($_ = <$remote>) {
    $_ =~ s/\r$//;  # trim annoying \r line-endings on some output
    print;
}
close($remote)	or die "Can't close socket: $!\n";

sub help {
   print <<EOF

pqotd - Perl Quote Of The Day (qotd) Client version $version

pqotd connects to the specified TCP port (defaults to qotd (17)) on the
specified host and displays the data that it is given.

Usage: pqotd [--help | --version] host [port [-v]]

-v         tells pqotd to be verbose in its output
           (limitation: must be third option)

--help     displays this help screen

--version  displays the version

pqotd can also be used for other protocols that just send data, such as
daytime (13) and systat (11).

Report bugs to Alan Ford <alan\@whirlnet.co.uk>

EOF
;
   exit;
}

sub version {
   print "pqotd version $version\n";
   exit;
}