head	1.1;
branch	1.1.1;
access;
symbols
	RELENG_8_4:1.1.1.1.0.76
	RELENG_9_1_0_RELEASE:1.1.1.1
	RELENG_9_1:1.1.1.1.0.74
	RELENG_9_1_BP:1.1.1.1
	RELENG_8_3_0_RELEASE:1.1.1.1
	RELENG_8_3:1.1.1.1.0.72
	RELENG_8_3_BP:1.1.1.1
	RELENG_9_0_0_RELEASE:1.1.1.1
	RELENG_9_0:1.1.1.1.0.70
	RELENG_9_0_BP:1.1.1.1
	RELENG_9:1.1.1.1.0.68
	RELENG_9_BP:1.1.1.1
	RELENG_7_4_0_RELEASE:1.1.1.1
	RELENG_8_2_0_RELEASE:1.1.1.1
	RELENG_7_4:1.1.1.1.0.66
	RELENG_7_4_BP:1.1.1.1
	RELENG_8_2:1.1.1.1.0.64
	RELENG_8_2_BP:1.1.1.1
	RELENG_8_1_0_RELEASE:1.1.1.1
	RELENG_8_1:1.1.1.1.0.62
	RELENG_8_1_BP:1.1.1.1
	RELENG_7_3_0_RELEASE:1.1.1.1
	RELENG_7_3:1.1.1.1.0.60
	RELENG_7_3_BP:1.1.1.1
	RELENG_8_0_0_RELEASE:1.1.1.1
	RELENG_8_0:1.1.1.1.0.58
	RELENG_8_0_BP:1.1.1.1
	RELENG_8:1.1.1.1.0.56
	RELENG_8_BP:1.1.1.1
	RELENG_7_2_0_RELEASE:1.1.1.1
	RELENG_7_2:1.1.1.1.0.54
	RELENG_7_2_BP:1.1.1.1
	RELENG_7_1_0_RELEASE:1.1.1.1
	RELENG_6_4_0_RELEASE:1.1.1.1
	RELENG_7_1:1.1.1.1.0.52
	RELENG_7_1_BP:1.1.1.1
	RELENG_6_4:1.1.1.1.0.50
	RELENG_6_4_BP:1.1.1.1
	RELENG_7_0_0_RELEASE:1.1.1.1
	RELENG_6_3_0_RELEASE:1.1.1.1
	RELENG_7_0:1.1.1.1.0.48
	RELENG_7_0_BP:1.1.1.1
	RELENG_6_3:1.1.1.1.0.46
	RELENG_6_3_BP:1.1.1.1
	RELENG_7:1.1.1.1.0.44
	RELENG_7_BP:1.1.1.1
	RELENG_6_2_0_RELEASE:1.1.1.1
	RELENG_6_2:1.1.1.1.0.42
	RELENG_6_2_BP:1.1.1.1
	RELENG_5_5_0_RELEASE:1.1.1.1
	RELENG_5_5:1.1.1.1.0.40
	RELENG_5_5_BP:1.1.1.1
	RELENG_6_1_0_RELEASE:1.1.1.1
	RELENG_6_1:1.1.1.1.0.38
	RELENG_6_1_BP:1.1.1.1
	RELENG_6_0_0_RELEASE:1.1.1.1
	RELENG_6_0:1.1.1.1.0.36
	RELENG_6_0_BP:1.1.1.1
	RELENG_6:1.1.1.1.0.34
	RELENG_6_BP:1.1.1.1
	RELENG_5_4_0_RELEASE:1.1.1.1
	RELENG_5_4:1.1.1.1.0.32
	RELENG_5_4_BP:1.1.1.1
	RELENG_4_11_0_RELEASE:1.1.1.1
	RELENG_4_11:1.1.1.1.0.30
	RELENG_4_11_BP:1.1.1.1
	RELENG_5_3_0_RELEASE:1.1.1.1
	RELENG_5_3:1.1.1.1.0.28
	RELENG_5_3_BP:1.1.1.1
	RELENG_5:1.1.1.1.0.26
	RELENG_5_BP:1.1.1.1
	v4_2_0:1.1.1.1
	RELENG_4_10_0_RELEASE:1.1.1.1
	RELENG_4_10:1.1.1.1.0.24
	RELENG_4_10_BP:1.1.1.1
	RELENG_5_2_1_RELEASE:1.1.1.1
	RELENG_5_2_0_RELEASE:1.1.1.1
	RELENG_5_2:1.1.1.1.0.22
	RELENG_5_2_BP:1.1.1.1
	RELENG_4_9_0_RELEASE:1.1.1.1
	RELENG_4_9:1.1.1.1.0.20
	RELENG_4_9_BP:1.1.1.1
	RELENG_5_1_0_RELEASE:1.1.1.1
	RELENG_5_1:1.1.1.1.0.18
	RELENG_5_1_BP:1.1.1.1
	RELENG_4_8_0_RELEASE:1.1.1.1
	RELENG_4_8:1.1.1.1.0.16
	RELENG_4_8_BP:1.1.1.1
	RELENG_5_0_0_RELEASE:1.1.1.1
	RELENG_5_0:1.1.1.1.0.14
	RELENG_5_0_BP:1.1.1.1
	v4_1_1b:1.1.1.1
	v4_1_1a:1.1.1.1
	RELENG_4_7_0_RELEASE:1.1.1.1
	RELENG_4_7:1.1.1.1.0.12
	RELENG_4_7_BP:1.1.1.1
	RELENG_4_6_2_RELEASE:1.1.1.1
	RELENG_4_6_1_RELEASE:1.1.1.1
	RELENG_4_6_0_RELEASE:1.1.1.1
	RELENG_4_6:1.1.1.1.0.10
	RELENG_4_6_BP:1.1.1.1
	RELENG_4_5_0_RELEASE:1.1.1.1
	RELENG_4_5:1.1.1.1.0.8
	RELENG_4_5_BP:1.1.1.1
	RELENG_4_4_0_RELEASE:1.1.1.1
	RELENG_4_4:1.1.1.1.0.6
	RELENG_4_4_BP:1.1.1.1
	v4_1_0:1.1.1.1
	RELENG_4_3_0_RELEASE:1.1.1.1
	RELENG_4_3:1.1.1.1.0.4
	RELENG_4_3_BP:1.1.1.1
	RELENG_4_2_0_RELEASE:1.1.1.1
	RELENG_4_1_1_RELEASE:1.1.1.1
	PRE_SMPNG:1.1.1.1
	RELENG_4_1_0_RELEASE:1.1.1.1
	RELENG_4_0_0_RELEASE:1.1.1.1
	RELENG_4:1.1.1.1.0.2
	RELENG_4_BP:1.1.1.1
	v4_0_99b:1.1.1.1
	v4_0_98f:1.1.1.1
	DMILLS:1.1.1;
locks; strict;
comment	@# @;


1.1
date	99.12.09.13.01.03;	author roberto;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	99.12.09.13.01.03;	author roberto;	state Exp;
branches
	1.1.1.1.76.1;
next	;

1.1.1.1.76.1
date	99.12.09.13.01.03;	author svnexp;	state dead;
branches;
next	1.1.1.1.76.2;

1.1.1.1.76.2
date	2013.03.28.13.01.48;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#!/bin/sh 
#
# ntpgroper host ...
#
# This script checks each hostname given as an argument to see if
# it is running NTP.  It reports one of the following messages (assume
# the host is named "dumbo.hp.com":
#
#   dumbo.hp.com not registered in DNS
#   dumbo.hp.com not responding to ping
#   dumbo.hp.com refused ntpq connection
#   dumbo.hp.com not responding to NTP
#   dumbo.hp.com answers NTP version 2, stratum: 3, ref: telford.nsa.hp.com
#   dumbo.hp.com answers NTP version 3, stratum: 3, ref: telford.nsa.hp.com
#
# It ain't pretty, but it is kinda useful.
#
# Walter Underwood, 11 Feb 1993, wunder@@hpl.hp.com
#
# converted to /bin/sh from /bin/ksh by scott@@ee.udel.edu 24 Mar 1993

PATH="/usr/local/etc:$PATH" export PATH

verbose=1
logfile=/tmp/cntp-log$$
ntpqlog=/tmp/cntp-ntpq$$

# I wrap the whole thing in parens so that it is possible to redirect
# all the output somewhere, if desired.
(
for host in $*
do
    # echo "Trying $host."

    gethost $host > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
        echo "$host not registered in DNS"
        continue
    fi

    ping $host 64 1 > /dev/null 2>&1 
    if [ $? -ne 0 ]
    then
        echo "$host not responding to ping"
	continue
    fi
    
    # Attempt to contact with version 3 ntp, then try version 2.
    for version in 3 2
    do

        ntpq -c "ntpversion $version" -p $host > $ntpqlog 2>&1

        if fgrep -s 'Connection refused' $ntpqlog
        then
            echo "$host refused ntpq connection"
            break
        fi

        responding=1
        fgrep -s 'timed out, nothing received' $ntpqlog > /dev/null && responding=0

        if   [ $responding -eq 1 ]
        then
	    ntpq -c "ntpversion $version" -c rl $host > $ntpqlog

            # First we extract the reference ID (usually a host or a clock)
            synchost=`fgrep "refid=" $ntpqlog`
            #synchost=${synchost##*refid=} # strip off the beginning of the line
            #synchost=${synchost%%,*}      # strip off the end  
	    synchost=`expr "$synchost" : '.*refid=\([^,]*\),.*'`

            # Next, we get the stratum
            stratum=`fgrep "stratum=" $ntpqlog`
            #stratum=${stratum##*stratum=}
            #stratum=${stratum%%,*}
	    stratum=`expr "$stratum" : '.*stratum=\([^,]*\),.*'`

	    echo "$host answers NTP version $version, stratum: $stratum, ref: $synchost"
            break;
        fi

	if [ $version -eq 2 -a $responding -eq 0 ]
        then
            echo "$host not responding to NTP"
        fi
    done
done
)
# ) >> $logfile

if [ -f $ntpqlog ]; then
    rm $ntpqlog
fi
@


1.1.1.1
log
@Virgin import of ntpd 4.0.98f
@
text
@@


1.1.1.1.76.1
log
@file ntp-groper was added on branch RELENG_8_4 on 2013-03-28 13:01:48 +0000
@
text
@d1 95
@


1.1.1.1.76.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 95
#!/bin/sh 
#
# ntpgroper host ...
#
# This script checks each hostname given as an argument to see if
# it is running NTP.  It reports one of the following messages (assume
# the host is named "dumbo.hp.com":
#
#   dumbo.hp.com not registered in DNS
#   dumbo.hp.com not responding to ping
#   dumbo.hp.com refused ntpq connection
#   dumbo.hp.com not responding to NTP
#   dumbo.hp.com answers NTP version 2, stratum: 3, ref: telford.nsa.hp.com
#   dumbo.hp.com answers NTP version 3, stratum: 3, ref: telford.nsa.hp.com
#
# It ain't pretty, but it is kinda useful.
#
# Walter Underwood, 11 Feb 1993, wunder@@hpl.hp.com
#
# converted to /bin/sh from /bin/ksh by scott@@ee.udel.edu 24 Mar 1993

PATH="/usr/local/etc:$PATH" export PATH

verbose=1
logfile=/tmp/cntp-log$$
ntpqlog=/tmp/cntp-ntpq$$

# I wrap the whole thing in parens so that it is possible to redirect
# all the output somewhere, if desired.
(
for host in $*
do
    # echo "Trying $host."

    gethost $host > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
        echo "$host not registered in DNS"
        continue
    fi

    ping $host 64 1 > /dev/null 2>&1 
    if [ $? -ne 0 ]
    then
        echo "$host not responding to ping"
	continue
    fi
    
    # Attempt to contact with version 3 ntp, then try version 2.
    for version in 3 2
    do

        ntpq -c "ntpversion $version" -p $host > $ntpqlog 2>&1

        if fgrep -s 'Connection refused' $ntpqlog
        then
            echo "$host refused ntpq connection"
            break
        fi

        responding=1
        fgrep -s 'timed out, nothing received' $ntpqlog > /dev/null && responding=0

        if   [ $responding -eq 1 ]
        then
	    ntpq -c "ntpversion $version" -c rl $host > $ntpqlog

            # First we extract the reference ID (usually a host or a clock)
            synchost=`fgrep "refid=" $ntpqlog`
            #synchost=${synchost##*refid=} # strip off the beginning of the line
            #synchost=${synchost%%,*}      # strip off the end  
	    synchost=`expr "$synchost" : '.*refid=\([^,]*\),.*'`

            # Next, we get the stratum
            stratum=`fgrep "stratum=" $ntpqlog`
            #stratum=${stratum##*stratum=}
            #stratum=${stratum%%,*}
	    stratum=`expr "$stratum" : '.*stratum=\([^,]*\),.*'`

	    echo "$host answers NTP version $version, stratum: $stratum, ref: $synchost"
            break;
        fi

	if [ $version -eq 2 -a $responding -eq 0 ]
        then
            echo "$host not responding to NTP"
        fi
    done
done
)
# ) >> $logfile

if [ -f $ntpqlog ]; then
    rm $ntpqlog
fi
@


