4 $passwd = 'nas-password';
7 $type = shift || 'snmp';
8 $nastype = shift || 'cisco';
10 $sessionid = shift || '';
16 $comm = shift || 'public';
18 if ($type eq 'telnet'){
23 die "No \$host argument given\n" if ($host eq '');
24 die "No \$username argument given\n" if ($username eq '');
26 if ($nastype eq 'cisco' && $type eq 'telnet'){
27 die "Usage: clearsession \$host telnet cisco \$username \$sessionid \$port\n" if ($port == 0);
29 if (eval require Net::Telnet::Cisco){
30 Net::Telnet::Cisco->import();
32 my $session = Net::Telnet::Cisco->new(Host => $host);
33 $session->login($login, $passwd);
36 my @output = $session->cmd("sh caller user $username");
37 foreach $line (@output){
38 if ($line =~ /User: $username, line (Vi\d+),/){
39 $session->cmd("clear interface $1");
44 $session->cmd("clear line $port\n");
50 if ($nastype eq 'cisco' && $type eq 'snmp'){
52 $SNMPGET="/usr/local/bin/snmpget";
53 $SNMPSET="/usr/local/bin/snmpset";
55 die "Could not find snmpwalk binary. Please make sure that the \$SNMPGET variable points to the right location\n" if (! -x $SNMPGET);
56 die "Could not find snmpset binary. Please make sure that the \$SNMPSET variable points to the right location\n" if (! -x $SNMPSET);
57 die "Usage: clearsession \$host snmp \$username cisco \$sessionid \$community\n" if ($sessionid eq '' || $comm eq '');
59 if ($sessionid ne '' && $username ne ''){
60 print "$SNMPGET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2.$sessionid\n";
61 $walk =`$SNMPGET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2.$sessionid`;
62 unless ($walk =~ /^$/){
63 if ($walk =~ /$username/){
64 print "FOUND: $username\n";
65 `$SNMPSET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.5.$sessionid i 1`;