#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Pod::Usage; use IO::Socket::INET; use POSIX qw(strftime); my $cb_server; GetOptions( 'server:s' => \$cb_server ) or pod2usage(2); my $paddr = '127.0.0.1'; my $port = 4571; if ($cb_server) { if ($cb_server =~ m/(.*):(.*)/) { $paddr = $1; $port = $2; } elsif ($cb_server =~ m/^([-.a-z0-9]+)$/i) { $paddr = $1; } else { pod2usage(2); } } my $s = IO::Socket::INET->new(PeerAddr => $paddr, PeerPort => $port, Timeout => 60); unless ($s) { print STDERR "$0: cannot connect to $paddr:$port: $!\n"; exit(1); } $s->print($ARGV[0], "\n"); my $res = $s->getline; unless ($res) { print STDERR "$0: no answer from $paddr:$port\n"; exit(1); } chomp $res; my ($code, $msg, $addr, $mx_server, $timestamp, $expire) = split(/:/, $res); print "$addr: $code\nMessage: $msg\n"; print "Server: $mx_server\n" if defined $mx_server; print "Unchanged since: ", strftime("%Y-%m-%dT%H:%M:%S%z", localtime($timestamp)), "\n" if defined $timestamp; print "Next check:" . strftime("%Y-%m-%dT%H:%M:%S%z", localtime($expire)), "\n" if defined $expire;