in reply to sockets: problems with daytime client
#!/usr/bin/perl use warnings; use strict; use IO::Socket; # su to root first, unless sudo is setup correctly for the commands my $datecommand='date -s'; #'set system time' command my $request ="HEAD / HTTP/1.0\r\nHost: \r\nUser-Agent:zzzdate\r\nPragm +a: no-cache\r\n\r\n"; my $socket = IO::Socket::INET->new ( Proto => 'tcp', PeerAddr => 'www.google.com', PeerPort => 80 ) or die "Can't connect $!\n"; # Send HEAD requests print "$request\n"; print $socket $request; while (defined (my $res = <$socket>) ) { print "$res\n"; if ( $res =~ /Date: / ) { # Like-> Date: Wed, 22 Oct 2008 18:30:46 GMT $res =~ s/Date: //; #print "$res\n"; print "Setting time... ", `$datecommand \"$res\"`; } } close $socket; #zero out adjtime if time keeps getting thrown off unexpectedly #open (TH,"> /etc/adjtime") or die "$!\n" #close TH;
|
|---|