Ascend Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

No Subject



>   We've got a few hundred P50s deployed, divided into 4 groups which share
> common passwords.  I'm planning on whipping up an Expect script to chew
> through a listing of IPs, telnet to each and change the telnet and full
> access passwords.  However, since I haven't actually used Expect before I
> figured I'd check to see if anyone had a similar tool already in use..?

Here's something that will query or change the phone number that gets
dialed by a Pipeline. It's reasonably reliable.

However, I don't recommend this approach -- it was pretty tough to get it
work as reliably as it does (which is not 100%). I recommand instead
using SNMP in combination with tftp. That works much better.

With tftp you can fetch or store a config. SNMP allows you to remotely
invoke the equivalent of the "tsave" or "trestore" command that allows
this tftp operation to take place.

The example script I have that uses my favored approach reads the SPIDs
out of a Pipeline. You must run it on a tftp server and change the
address at line 22 to your own address.

-Phil
#!/local/bin/perl

use Socket;
use SNMP;

$dir = "/tftpboot";
$filename = "getspids.$$";

$from = $ARGV[0];
$community = $ARGV[1];
if (($from eq "") || ($community eq "")) {
	print STDERR "Usage: $0 host community\n";
	exit 1;
}

	open(CONFIG, ">$dir/$filename");
	chmod 0666, "$dir/$filename";
	close CONFIG;

	$session = new SNMP::Session ( DestHost => $from, Community => $community );
	SNMP::loadModules("ASCEND-MIB");
	$session->set("sysConfigTftpHostAddr.0", unpack("I", pack("C4", 205,236,182,53)));
	if (($_ = $session->{ErrorStr}) ne "") {
		print "$from Setting HostAddr: $_\n";
		unlink "$dir/$filename";
		exit 1;
	}
	$session->set("sysConfigTftpFilename.0", $filename);
	if (($_ = $session->{ErrorStr}) ne "") {
		print "$from Setting Filename: $_\n";
		unlink "$dir/$filename";
		exit 1;
	}
	$session->set("sysConfigTftpCmd.0", 1);
	if (($_ = $session->{ErrorStr}) ne "") {
		print "$from Sending tftp command: $_\n";
		unlink "$dir/$filename";
		exit 1;
	}

	$status = $session->get("sysConfigTftpStatus.0");
	while ($status == 17) {
		sleep 1;
		$status = $session->get("sysConfigTftpStatus.0");
	}

	undef $session;

	$spid1 = "";
	$spid2 = "";
	if ($status == 1) {
		open(CONFIG, "<$dir/$filename");
		while (<CONFIG>) {
			$spid1 = $1 if (/Pri SPID=([0-9]+)/);
			$spid2 = $1 if (/Sec SPID=([0-9]+)/);
		}
		close CONFIG;
		print "$from\t$spid1 $spid2\n";
	} else {
		print "$from\tstatus=$status\n";
	}
	unlink "$dir/$filename";
#!/opt/tcl/bin/expect --

log_user 0
set timeout 5

set ip [lrange $argv 0 0]
set password [lrange $argv 1 1]
set newnumber [lrange $argv 2 2]

set argc [llength $argv]
if {$argc < 2 || $argc > 3} then {
	puts stderr "Usage: $argv0 ip-address password \[new number\]"
	exit 1
}

spawn telnet $ip
expect {
	timeout		{puts {Timeout connecting to router}; exit 1}
	Connected
}
expect {
	timeout		{puts {Router is probably not a Pipeline}; exit 1}
	"Enter password:"
}
send "$password\r"
expect {
	"Enter password:"	{puts {Password does not work}; exit 1}
	timeout		{puts {Timeout sending password}; exit 1}
	">Configure"
}
send "\016"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	">00-000"
}
send "\016"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	">20-000"
}
send "\r"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	">20-100"
}
send "\r"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	">20-101"
}
send "\r"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	-re "Dial #=(\[0-9\]*) "
}

set number "$expect_out(1,string)"

if {([string compare $newnumber ""] != 0) && ([string compare $newnumber $number] != 0)} {
	# Set a nuew phone number
	send "\016"
	expect {
		timeout	{puts stderr {Unable to navigate menus}; exit 1}
		">Active="
	}
	send "\016"
	expect {
		timeout	{puts stderr {Unable to navigate menus}; exit 1}
		">Encaps="
	}
	send "\016"
	expect {
		timeout	{puts stderr {Unable to navigate menus}; exit 1}
		">Dial #="
	}
	send "\r"
	expect {
		timeout	{puts stderr {No permission to set new number?}; exit 1}
		{ \[}
	}
	send "$newnumber\r"
	expect {
		timeout	{puts stderr {Unable to navigate menus}; exit 1}
		">Dial #="
	}
	send "\033"
	expect {
		timeout	{puts stderr {Unable to navigate menus}; exit 1}
		"2=Exit"
	}
	send "2"
	expect {
		timeout	{puts stderr {Unable to save changes}; exit 1}
		"Profile stored"
	}
	send " "
	expect {
		timeout	{puts stderr {Unable to save changes}; exit 1}
		">20-101"
	}
}

send "\004"
expect {
	timeout	{puts {Unable to navigate menus}; exit 1}
	"C=Close TELNET"
}
send "c"
expect "closed by foreign host"

if {[string compare $newnumber ""] == 0} {
	puts $number
}

exit 0