Kali ini gw mo share script perl untuk mengganti password mikrotik secara serentak. Nih sob, gunanya kalo misalkan lu punya network nih ye, ntah skala rt/rwnet, kabupaten-net, maupun akap-net (antar kota antar propinsi-net) haha :D pernah ga kebayang kalo misalkan ada salah satu perangkat mikrotik ente ketahuan passwordnya. Tentu jadi persoalan klo musti ganti satu satu. Nah pake script ini ente bisa jalanin cukup pake script ini, ntar secara serentak semua perangkat mikrotik ente keubah passwordnya. Eits tapi ente tetep musti bikin password list dulu sebelum dieksekusi. Gunanya buat diproses di program perl nya. Ok langsung aja bikin file pass.txt yang dalemnya dengan format host::user::pass misale 10.10.20.2::admin::ganteng. Berikut script perl nya
#!/usr/bin/perlsimpan dengan nama terserah, misale changepass.pl jangan lupa chmod 777 changepass.pl lalu dieksekusi ./changepass.pl
# Update multiple mikrotiks
# change password script
# Copyright (C) 2004 Butch Evans
# butche@butchevans.com
#########################
# Configuration section #
#########################
# The username and password file with connection information
# to connect to your router. This user MUST have read and write permissions
# Each line in this file is in the format:
#Â routerip::user::userpassword
my $passwdfile = "pass.txt";
# If you want to see some output, set this to "1"
my $debug = 1;
# Set the NEW password here
my $newpass = "rahox";
#############################
# End configuration section #
#############################
# You do not need to change anything below here
# unless you know what you are doing
use strict;
use Net::Telnet ();
# Grab the hosts file (with passwords)
if (! ( -f $passwdfile ) ){
print "ERROR: Password file $passwdfile does not exist!\n\n";
die;
}
# Slurp the script file into memory
open (PASSWDLIST,$passwdfile);
my @hostlist = <PASSWDLIST> ;
close(PASSWDLIST);
my $hostlist;
my $hostline;
my $host;
my $username;
my $passwd;
#Now, we just cycle through the list of hosts
foreach $hostline (@hostlist){
chomp $hostline;
($host,$username,$passwd) = split("::",$hostline);
# Login to the server
if ($debug){
print "Connecting to ". $host ."\n";
}
my $t = new Net::Telnet (Host => $host);
$t->errmode( sub { print "ERROR:" . join('|', @_) . "\n"; } );
$t->login($username, $passwd);
my $errormsg = $t->errmsg;
if ( $errormsg ne "") {
next; }
# DO THE WORK
my @changepass = $t->cmd("/user set ". $username ." password=". $newpass);
if ($debug) {
print "Password change successful\n";
}
$t->close;
}
exit;
Kalo udah ntar kek gini
root@nms ~ # ./changepass.pl
Connecting to 10.10.20.2
Password change successful
Yak, sekian semoga bermanfaat, yang masih error bisa comment di bawah
0 comments:
Post a Comment