Script to change snmp write/read permissions

Is there a script to change the snmp write/read parameter?
I've got many PMP 450 Subscriber Module that need this... please
thanks

Hi Fabiovi,

Currently we do not have script for changing the SNMP parameters on the PMP radios. We have to login to the radio manually for changing the SNMP parameters.

Regards,

Sanjay Kumar.

Back in 2009 I posted a perl script that will do this on Canopy radios.  Turns out it's also suited to work with PMP450.  Tested and used on linux (Ubuntu)

#!/usr/bin/perl
#
# quickie script to change read-only to read/write SNMP on a single SM/AP
# Copyright 2009-2016 Joel NewKirk 
# jnewkirk@canmon.us 
# subject to the MIT license as presented here: http://www.opensource.org/licenses/mit-license.php

$|=1;
my $debug=2;
use IO::Socket::INET;

my $ip=shift;
my $canpass=shift;

makewriteable($ip,$canpass);
exit;

sub makewriteable()
{
my ($ip,$canpass)=@_;
my $host=$ip.":80";
my $EOL = “\015\012”;
my $remote=IO::Socket::INET->new($host) or return;
$remote->autoflush(1);
print $remote “GET /login.cgi?CanopyUsername=admin&CanopyPassword=”.$canpass." HTTP/1.1".$EOL;
print $remote ‘User-Agent: Mozilla/5.0’. $EOL;
print $remote $EOL;
print $remote $EOL;
while (<$remote>) {
if (/Session=(.*)"/)
{
$sessid=$1;
my $remote1=IO::Socket::INET->new($host) or next;
$remote1->autoflush(1);
my $remote2=IO::Socket::INET->new($host) or next;
$remote2->autoflush(1);
print $remote2 “GET /himom.cgi?ok=Save+Changes&1366:SNMPReadOnly=0&Session=$sessid HTTP/1.1”.$EOL;
print $remote2 ‘User-Agent: Mozilla/5.0’. $EOL;
print $remote2 $EOL;
print $remote2 $EOL;
print “$host: GET /himom.cgi?ok=Save+Changes&1366:SNMPReadOnly=0&Session=$sessid HTTP/1.1\n”;
last;
}
}
}

Save the script, make it executable, and when run pass it an IP address followed by password. (like “./makewriteable.pl 10.11.12.13 1234pass”)

The two lines near the end with 'GET /himom.cgi' are subject to change - "1366:SNMPReadOnly" is the field name on our PMP450i-900 SMs right now running 14.1.1 firmware.  The numeric prefix may be different on different gear or firmware.  If the script seems to work but doesn't change anything, log into the SM with web browser and view the source of the Configuration->SNMP view, looking for the correct numeric prefix in the lines below:

<div class='radiobuttons'>
<input type='radio' name='1366:SNMPReadOnly' value='1' checked='checked' id='SNMPReadOnlyTrue' onclick=' RadioClick();' onchange=''  />Read Only<br/>
<input type='radio' name='1366:SNMPReadOnly' value='0'  id='SNMPReadOnlyFalse' onclick=' RadioClick();' onchange=''  />Read / Write<br/>
</div>

If you have a list of IPs, one per line, then you can feed them to the script with something like "for IP in $(cat iplist.txt);do makewriteable.pl $IP 1234pass;done".  (assumes '1234pass' is admin password) Other shell gymnastics, like extracting IPs from DB, are left to the reader... ;)

j

1 Like

This is awesome. Thank you!

OK, I revisited this script and ended up with the version below that runs as an ExternalTool from CNUT.  

You can also cut/paste the makewriteable() subroutine into the CLI version above to gain automatic field-name support.  (it retrieves the Configuration->SNMP page and identifies the numeric prefix needed for each unit, so no more editing to match deployed software versions)

j

#!/usr/bin/perl
#
# script to change read-only to read/write SNMP on a list of radios provided by CNUT
# 
# Copyright 2016 Joel NewKirk 
# jnewkirk@canmon.us 
#
# subject to the MIT license as presented here: http://www.opensource.org/licenses/mit-license.php

$|=1;
use IO::Socket::INET;

while (<STDIN>)
{
$_ =~ /^(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);(.?);./;
makewriteable($1,$6);
}

sub makewriteable()
{
my ($ip,$canpass)=@_;
my $host=$ip.":80";
my $EOL = “\015\012”;
my $remote=IO::Socket::INET->new($host) or return;
$remote->autoflush(1);
print $remote “GET /login.cgi?CanopyUsername=admin&CanopyPassword=”.$canpass." HTTP/1.1".$EOL;
print $remote ‘User-Agent: Mozilla/5.0’. $EOL;
print $remote $EOL;
print $remote $EOL;
while (<$remote>) {
if (/Session=(.)"/)
{
$sessid=$1;
my $remote1=IO::Socket::INET->new($host) or next;
$remote1->autoflush(1);
my $prefix=1366;
print $remote1 “GET /main.cgi?catindex=1&pageindex=7&Session=$sessid HTTP/1.1”.$EOL;
print $remote1 ‘User-Agent: Mozilla/5.0’. $EOL;
print $remote1 $EOL;
print $remote1 $EOL;
while (<$remote1>) {
if (/name=’(.
):SNMPReadOnly’/)
{
$prefix=$1;

print “Found $prefix:SNMPReadOnly for $host\n”;

                last;
            }
        }
        my $remote2=IO::Socket::INET-&gt;new($host) or next;
        $remote2-&gt;autoflush(1);
        print $remote2 "GET /himom.cgi?ok=Save+Changes&amp;$prefix:SNMPReadOnly=0&amp;Session=$sessid HTTP/1.1".$EOL;
        print $remote2 'User-Agent: Mozilla/5.0'. $EOL;
        print $remote2 $EOL;
        print $remote2 $EOL;
        print "$host: GET /himom.cgi?ok=Save+Changes&amp;$prefix:SNMPReadOnly=0&amp;Session=$sessid HTTP/1.1\n";
        last;
    }
}

}

2 Likes