use strict;
use warnings;
#use 5.010;
use IO::Socket;
#my $host = 'localhost';
#my $host = 'time.nist.gov';
#my $host = 'nist1-sj.ustiming.org';
my $host = 'time-nw.nist.gov'; # pester microsoft
my $port = 'daytime(13)';
my $sock = IO::Socket::INET->new(
Proto => 'tcp',
PeerHost => $host,
PeerPort => $port,
) or die "cannot connect: $!";
while (<$sock>) {
s/^[[:space:]]+//;
s/[[:space:]]+\z//s;
next if /^$/;
# NIST Daytime Protocol format
# http://tf.nist.gov/service/its.htm
# JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM
if ($_ =~ /^(\d+)\s+(\d{2})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{
+2})\s+(\d{2})\s+(\d)\s+(\d)\s+([0-9\.]+)\s+UTC\(NIST\)\s+(.)/)
{
my ($mjd, $yr, $mo, $da) = ($1,$2,$3,$4);
my ($hour, $min, $sec, $dst, $lsec) = ($5,$6,$7,$8,$9);
my ($health, $msADV, $otm) = ($10,$11,$12);
print "NIST: $yr-$mo-$da $hour:$min:$sec\n";
}
else
{
print "$_\n";
}
}
|