added daytime_query.pl
This commit is contained in:
parent
350939e819
commit
561c673db1
1 changed files with 37 additions and 0 deletions
37
time/daytime_query.pl
Executable file
37
time/daytime_query.pl
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/perl
|
||||
# Script Fragt den RFC 868 Timeserver ab
|
||||
# und liefert die Zeit
|
||||
#
|
||||
# 20060721 Peter Baumann <dev@linuxnet.ch>
|
||||
|
||||
use IO::Socket;
|
||||
|
||||
# Einen DaytimeServer anzapfen
|
||||
$hostname = "172.16.1.40";
|
||||
|
||||
# Serverport
|
||||
use constant SVPORT => 37;
|
||||
|
||||
# Differenz zwischen 1.1.1900 (Time-Server)
|
||||
# und 1.1.1970 (UNIX-Epoche)
|
||||
use constant KORR => 2208988800;
|
||||
|
||||
my $cur_time = &get_time;
|
||||
print "Die Server Zeit ist $cur_time\n";
|
||||
|
||||
# Zeit vom anderen Server holen
|
||||
sub get_time
|
||||
{
|
||||
my ($binarytime, $servertime);
|
||||
my $ts_sock = new IO::Socket::INET (
|
||||
PeerAddr => $hostname,
|
||||
PeerPort => SVPORT,
|
||||
Proto => 'tcp')
|
||||
or die "can't create local socket: $@\n";
|
||||
|
||||
read($ts_sock,$binarytime,4);
|
||||
$ts_sock->close();
|
||||
$servertime = unpack('N',$binarytime);
|
||||
$servertime = localtime($servertime - KORR);
|
||||
return "$servertime";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue