SOA Checking

#!/bin/sh
# Verify existence of SOA records for device's domain and its IP subnets
NAME=$(basename $0)
[ $# -ne 1 ] && echo "Usage: $NAME <hostname>" && exit
HOSTNAME="$1"
[ -z "$HOSTNAME" ] && echo "Hostname cannot be empty!" && exit
DOMAIN=$(echo "$HOSTNAME" | sed 's/^[^.]*\.//')
[ -z "$DOMAIN" -o "$DOMAIN" == "$HOSTNAME" ] && echo "Hostname without a valid domain!" \
&& exit
IP=$(dig +short "$HOSTNAME" | tail -n1)
[ -z "$IP" ] && echo "Hostname without a valid IP!" && exit
dig SOA "$DOMAIN" | grep '^;; ANSWER SECTION:' > /dev/null \
&& echo "SOA record exists for domain \"$DOMAIN\"" \
|| echo "No SOA record for for domain \"$DOMAIN\"!"
SUBNET="$IP"
for NETMASK in 24 16 8; do
SUBNET=$(echo "$SUBNET" | sed 's/\.[^.]*$//')
SUFFIX="$SUFFIX.0"
dig SOA -x "$SUBNET" 2> /dev/null | grep '^;; ANSWER SECTION:' > /dev/null \
&& echo "SOA record exists for subnet \"${SUBNET}${SUFFIX}/$NETMASK\"" \
&& exit
done
echo "No SOA record for any of \"$IP\" subnets!"
view raw soa-checker.sh hosted with ❤ by GitHub
#!/usr/bin/env perl
# Verify existence of SOA records for device's domain and its IP subnets
use strict;
use warnings;
use File::Basename;
use Net::DNS;
use Socket;
die 'Usage: ', basename($0), " <hostname>\n"
unless scalar @ARGV == 1;
die "Hostname cannot be empty!\n"
unless length( my $hostname = $ARGV[0] );
die "Hostname without a valid domain!\n"
unless ( $hostname =~ /^[^.]*\.(.*)/ && length( my $domain = $1 ) );
die "Hostname without a valid IP!\n"
unless my $ip = inet_aton $hostname;
$ip = inet_ntoa $ip;
my $res = Net::DNS::Resolver->new;
if ( $res->query( $domain, 'SOA' ) ) {
print "SOA record exists for domain \"$domain\"\n";
}
else {
print "No SOA record for for domain \"$domain\"\n";
}
my @rsubnet = reverse split '\.', $ip;
my $suffix = '';
for my $netmask ( 24, 16, 8 ) {
shift @rsubnet;
$suffix .= '.0';
if ( $res->query( join( '.', @rsubnet ) . '.in-addr.arpa', 'SOA' ) ) {
my $subnet = join('.', reverse @rsubnet );
die "SOA record exists for subnet \"$subnet$suffix/$netmask\"\n";
}
}
print "No SOA record for any of \"$ip\" subnets!\n";
view raw soap-checker.pl hosted with ❤ by GitHub
#!/usr/bin/env php
<?php
// Verify existence of SOA records for device's domain and its IP subnets
if ( count($argv) != 2 ) {
exit('Usage: ' . basename($argv[0]) . " <hostname>\n");
}
if ( strlen($hostname = $argv[1]) <= 0 ) {
exit("Hostname cannot be empty!\n");
}
preg_match('/^[^.]*\.(.*)/', $hostname, $matches);
if ( count($matches) != 2 || strlen($domain = $matches[1]) <= 0 ) {
exit("Hostname without a valid domain!\n");
}
if ( strlen($ip = gethostbyname($hostname)) <= 0 || $ip == $hostname ) {
exit("Hostname without a valid IP!\n");
}
$soa = dns_get_record($domain, DNS_SOA);
if ( count($soa) == 1 && $soa[0]['type'] == 'SOA' ) {
echo "SOA record exists for domain \"$domain\"\n";
} else {
echo "No SOA record for for domain \"$domain\"\n";
}
$rsubnet = array_reverse(explode('.', $ip));
$suffix = '';
foreach( array(24, 16, 8) as $netmask ) {
array_shift($rsubnet);
$suffix .= '.0';
$soa = dns_get_record(implode('.', $rsubnet) . '.in-addr.arpa', DNS_SOA);
if ( count($soa) == 1 && $soa[0]['type'] == 'SOA' ) {
$subnet = implode('.', array_reverse($rsubnet));
exit("SOA record exists for subnet \"$subnet$suffix/$netmask\"\n");
}
}
echo "No SOA record for any of \"$ip\" subnets!\n";

RHEL Subscription

Register a new system usig RedHat username and password and subscribe it to default and optional channels:

subscription-manager register
subscription-manager subscribe --auto
subscription-manager repos --enable=rhel-6-server-optional-rpms