Courtesy of Randal L. Schwartz, in http://www.sysadmin.org, July 2003

Hit the US Time website via the daytime protocol

#!/usr/bin/perl
use strict;
use IO::Socket::INET qw(CRLF);

my $client = IO::Socket::INET->new('time.gov:daytime')
   or die "new: $@";
{
   local $/;
   $_ = <$client>;
}

if (defined $_)
{
   print
   "response from ",
   $client->peerhost,
   " port ",
   $client->peerport,
   " was:\n$_";
}

Grabbing the entire html dump of its webpage

#!/usr/bin/perl
use strict;
use IO::Socket::INET qw(CRLF);

my $client = IO::Socket::INET->new('time.gov:http')
   or die "new: $@";

print $client "GET / HTTP/1.0", CRLF, CRLF;
print while <$client>;

Same thing, but a simpler method

#!/usr/bin/perl
use strict;
use LWP::Simple;
getprint("http://www.time.gov");

-- MattWalsh - 06 Aug 2003

Topic revision: r1 - 06 Aug 2003 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback