#!/usr/bin/perl
########################################################################
#                                                                      #
#    testrad.pl                   InnerCite                            #
#                                 Mike Machado <mike@innercite.com>    #
#                                 15 Jun 2000                          #
#                                                                      #
#    Perl version of radtest                                           #
#                                                                      #
#                   Copyright under same terms as Cistron RADIUS       #
#                                                                      #
########################################################################

if ($#ARGV ne 4) {
	print "Usage: <radius server> <radius secret> <local IP> <username> <password>\n";
	exit;
}

my $radhost = shift;
my $radsecret = shift;
my $myip = shift;
my $username = shift;
my $password = shift;

use Authen::Radius;

	my $r = new Authen::Radius(Host => $radhost, Secret => $radsecret);
	Authen::Radius->load_dictionary;
	$r->add_attributes (
                       { Name => '1', Value => $username },
                       { Name => '2', Value => $password },
                       { Name => '4', Value => $myip },
                       { Name => '6', Value => '2' },
                       { Name => '7', Value => '1' }
        );
	$r->send_packet (1) and $authed = $r->recv_packet;
	if ($authed ne ACCESS_ACCEPT) {
		print "Authenticate failure for $username/$password\n";
		exit;
	}
	print "Authentication Accepted for $username/$password\n";
	my @attribs = $r->get_attributes;
        for my $attr (@attribs) {
		print "\t$attr->{Name} = $attr->{Value}\n";
        }
