init III
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
perl convert.pl /srv/tftp/convert.txt /srv/tftp/network-confg
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
vi /srv/tftp/convert.txt
|
||||
./CreateNetworkTemplateForTFTP.sh
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Net::SNMP;
|
||||
|
||||
my $i=@ARGV;
|
||||
die "\nZu wenige Parameter!\n\nStartTftpDownload.pl <Router-IP> <TFTP-IP> <community> <Source> <Destination> <File>\n
|
||||
Source
|
||||
1: networkFile
|
||||
3: startupConfig
|
||||
4: runningConfig
|
||||
|
||||
Destination
|
||||
1: networkFile
|
||||
3: startupConfig
|
||||
4: runningConfig
|
||||
|
||||
Example
|
||||
C:\\>StartTftpDownload.pl 172.23.210.151 172.23.210.222 5NMP-Wr1t3-(0mm 1 4 getit.conf
|
||||
" if $i<6;
|
||||
|
||||
print "\n";
|
||||
|
||||
my $ROUT = $ARGV[0];
|
||||
my $TFTP = $ARGV[1];
|
||||
my $COMM = $ARGV[2];
|
||||
my $SOUR = $ARGV[3];
|
||||
my $DEST = $ARGV[4];
|
||||
my $FILE = $ARGV[5];
|
||||
|
||||
print "\nOpen SNMP session\n";
|
||||
my ($session, $error) = Net::SNMP->session(
|
||||
-hostname => $ROUT,
|
||||
-version => 'snmpv2',
|
||||
-community => $COMM,
|
||||
);
|
||||
|
||||
if (!defined $session) {
|
||||
printf "ERROR: %s.\n", $error;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
print "Send SNMP set requests\n";
|
||||
my $SES=".111";
|
||||
my $OID="1.3.6.1.4.1.9.9.96.1.1.1.1.2" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, INTEGER, '1' ], ); #The ConfigCopyProtocol is set to TFTP
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.3" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, INTEGER, $SOUR ], ); #Set the SourceFileType to networkfile #running-config
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.4" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, INTEGER, $DEST ], ); #Set the DestinationFileType to running-config #networkfile
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.5" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, IPADDRESS, $TFTP ], ); #Sets the ServerAddress to the IP address of the TFTP server
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.6" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, OCTET_STRING, $FILE ], ); #Sets the CopyFilename to your desired file name.
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.14" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, INTEGER, '1' ], ); #Sets the CopyStatus to active which starts the copy process.
|
||||
|
||||
|
||||
$OID="1.3.6.1.4.1.9.9.96.1.1.1.1.14" . $SES;
|
||||
$session->set_request(-varbindlist => [ $OID, INTEGER, '6' ], ); #Sets the CopyStatus to delete which cleans all saved informations out of the MIB
|
||||
|
||||
exit;
|
||||
print "Finished\n";
|
||||
|
||||
#
|
||||
#ccConfigCopyProtocol
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.2
|
||||
#Type: INTEGER
|
||||
#Options:tftp(1)
|
||||
#ftp(2)
|
||||
#rcp(3)
|
||||
#scp(4)
|
||||
#sftp(5)
|
||||
#Description: Defines whicn protocol is used for the copy process. TFTP is default
|
||||
|
||||
|
||||
#ccCopySourceFileType
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.3
|
||||
#Type: INTEGER
|
||||
#Options: networkFile(1)
|
||||
#iosFile(2)
|
||||
#startupConfig(3)
|
||||
#runningConfig(4)
|
||||
#terminal(5)
|
||||
#Descripton: Defines the source. Either the Source or the DestinatioFileType have to be set to startupConfig or runningConfig. Furthermore the SourceFileType has to be different to the DestinationFileType.
|
||||
|
||||
|
||||
#ccCopyDestFileType
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.4
|
||||
#Type: INTEGER
|
||||
#Options: networkFile(1)
|
||||
#iosFile(2)
|
||||
#startupConfig(3)
|
||||
#runningConfig(4)
|
||||
#terminal(5)
|
||||
#Description: Defines the destination.Either the Source or the DestinatioFileType have to be set to startupConfig or runningConfig. Furthermore the SourceFileType has to be different to the DestinationFileType.
|
||||
|
||||
|
||||
#ccCopyServerAddress
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.5
|
||||
#Type: IP Address
|
||||
#Description: Sets the address of the server to which the file will be copied to. Values like 0.0.0.0 or FF.FF.FF.FF are not allowed for this OID.
|
||||
|
||||
|
||||
#ccCopyFileName
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.6
|
||||
#Type: STRING
|
||||
#Description: Sets the name of the destination or source file. This OID has to be set as far as the destination or sourceFileType are set to networkFile or iosFile.
|
||||
|
||||
|
||||
#ccCopyUserName
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.7
|
||||
#Type: STRING
|
||||
#Description: Sets a username for FTP, RCP, SFTP or SCP. This will overwrite the user name which might have been set over the rcmd remote-username <username> command if RCP is used as protocol.
|
||||
|
||||
|
||||
#ccCopyUserPassword
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.8
|
||||
#Type: STRING
|
||||
#Description: Sets the password for FTP, RCP, SFTP or SCP
|
||||
|
||||
|
||||
#ccCopyNotificationOnCompletion
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.9
|
||||
#Type: INTEGER
|
||||
#Description: Defines if a notification has to be sent after the process has ended.
|
||||
|
||||
|
||||
#ccCopyState
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.10
|
||||
#Type: INTEGER
|
||||
#Options: waiting(1)
|
||||
#running(2)
|
||||
#successful(3)
|
||||
#failed(4)
|
||||
#Description: Shows the copy process’ status. This value will be set after the COPYEntryRowStatus has been set to active.
|
||||
|
||||
|
||||
#ccCopyTimeStarted
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.11
|
||||
#Type: TimeStamp
|
||||
#Description: Shows the last start time of the process or zero if the process never changed the status to running.
|
||||
|
||||
|
||||
#ccCopyTimeCompleted
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.12
|
||||
#Type: TimeStamp
|
||||
#Description: Shows the last time after the process changed from running to successful or failed.
|
||||
|
||||
|
||||
#ccCopyFailCause
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.13
|
||||
#Type: INTEGER
|
||||
#Options: unknown(1)
|
||||
#badFileName(2)
|
||||
#timeout(3)
|
||||
#noMem(4)
|
||||
#noConfig(5)
|
||||
#unsupportedProtocol(6)
|
||||
#someConfigApplyFailed(7)
|
||||
#Description: Shows why the process failed
|
||||
|
||||
|
||||
#ccCopyEntryRowStatus
|
||||
#OID: 1.3.6.1.4.1.9.9.96.1.1.1.1.14
|
||||
#Type: INTEGER
|
||||
#Options: active(1)
|
||||
#notInService(2)
|
||||
#createAndGo(4)
|
||||
#createAndWait(5)
|
||||
#destroy(6)
|
||||
#Description: Shows the process’ status
|
||||
#
|
||||
73
Linux Routerkonfiguration per tftp/RouterConfig/convert.pl
Normal file
73
Linux Routerkonfiguration per tftp/RouterConfig/convert.pl
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
$i=@ARGV;
|
||||
die "Zu wenige Parameter!\nconvert.pl <Eingabedatei> <Ausgabedatei>" if $i<2;
|
||||
|
||||
print "\n";
|
||||
print "Eingabedatei $ARGV[0]\n";
|
||||
print "Ausgabedatei $ARGV[1]\n";
|
||||
|
||||
|
||||
open IN, "<$ARGV[0]";
|
||||
open OUT, ">$ARGV[1]";
|
||||
|
||||
|
||||
@INF=<IN>;
|
||||
foreach (@INF) {
|
||||
chomp;
|
||||
router() if ($_ =~ /^!!ROUTER/);
|
||||
router() if ($_ =~ /^!!SWITCH/);
|
||||
router() if ($_ =~ /^!!FIREWALL/);
|
||||
}
|
||||
|
||||
close IN;
|
||||
close OUT;
|
||||
|
||||
sub router {
|
||||
$read_v=0;
|
||||
|
||||
# Variablen lesen
|
||||
foreach (@INF) {
|
||||
$read_v=1 if ($_ =~ /^!!VARIABLEN/);
|
||||
last if ($_ =~ /^!!CONFIG/);
|
||||
next if ($_ =~ /^!/);
|
||||
read_var($_) if ($read_v);
|
||||
}
|
||||
|
||||
# Konfig lesen
|
||||
$read_c=0;
|
||||
foreach (@INF) {
|
||||
chomp;
|
||||
$read_c=1 if ($_ =~ /^!!CONFIG/);
|
||||
if ($read_c) {
|
||||
if($_ =~ /<.*>/) {
|
||||
($vn)=$_=~/(<.*>)/;
|
||||
$_ =~ s/$vn/$VARS{$vn}/;
|
||||
next if ($VARS{$vn} eq "");
|
||||
}
|
||||
# und schreiben
|
||||
printf OUT "$_\n";
|
||||
}
|
||||
}
|
||||
# hostname-confg erstellen
|
||||
($pfad,$file)=$ARGV[1]=~/(.*)\/([^\/]*)$/;
|
||||
$hostname=$pfad.'/'.$VARS{'<HOSTNAME>'}.'-confg';
|
||||
print "Ausgabedatei 2 $hostname\n";
|
||||
open HN, ">$hostname";
|
||||
printf HN "\n!\nend\n\n";
|
||||
close HN;
|
||||
}
|
||||
|
||||
sub switch {
|
||||
}
|
||||
|
||||
sub firewall {
|
||||
}
|
||||
|
||||
sub read_var {
|
||||
$l=$_[0];
|
||||
if ($l=~ /<.*>.*=.*/) {
|
||||
($vn, $vv) = $l =~/(<.*>).*=[\s]*(.*)/;
|
||||
$VARS{$vn}=$vv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user