?? cfgmaker_ip
字號:
'140'=>'Dynamic synchronous Transfer Mode (DTM)', '141'=>'Data Communications Network', '142'=>'IP Forwarding Interface' ); ParseOptions(); my($community,$router) = ($1,$2) if $ARGV[0] =~ /(.*)\@(.*)/; Usage() unless $community && $router; if ($Template) { open(TEMPL,$Template) or die "Can't open template file: $Template: !$\n"; } print "# cfgmaker was run with args: $argz\n"; print "# Add a WorkDir: /some/path line to this file\n\n"; print "WorkDir: $WorkDir\n\n" if ($WorkDir); if ($Template) { print "# included from $Template\n"; while (<TEMPL>) { s/\t/ /g; #replace tabs by spac next if /^\s+$/; #ignore white space next if /^\s*\#/; #ignore comments print ; } print "# /included from $Template\n"; print "\n"; } print "Directory[^]: $router\n\n" if ($Gsubdir); $session = SNMP_Session->open ($router, $community, 161) || die "Error opening SNMP session to $router"; my($sysDescr,$sysContact,$sysName,$sysLocation,$ifNumber,$sysObjectID) = snmpget("$community\@$router", 'sysDescr','sysContact','sysName', 'sysLocation', 'ifNumber', 'sysObjectID'); my $coSysDescr = $sysDescr; $sysDescr =~ s/[\r\n]+/<BR>/g; # Change returns to <BR> $coSysDescr =~ s/[\r\n]+/\n# /g; # Change returns to commented my($cisco_router_sysid) = '1\.3\.6\.1\.4\.1\.9'; my($livingston_router_sysid) = '1\.3\.6\.1\.4\.1\.307'; my($ciscobox) = ($sysObjectID =~ /^$cisco_router_sysid/); my($portmaster) = ($sysObjectID =~ /^$livingston_router_sysid/); print <<ECHO if ($comments);####################################################################### Description: $coSysDescr# Contact: $sysContact# System Name: $sysName# Location: $sysLocation#.....................................................................ECHO $session->map_table ([[1,3,6,1,2,1,4,20,1,1], # ipAdEntAddr [1,3,6,1,2,1,4,20,1,2]], # ipAdEntIf sub ($@) { my ($index, $ipadentaddr, $ipadentif) = @_; grep (defined $_ && ($_=pretty_print $_), ($ipadentif, $ipadentaddr)); $ipaddr{$ipadentif} = $ipadentaddr if !$ipset{$ipadentif}; $iphost{$ipadentif} = gethostbyaddr(pack('C4',split(/\./,$ipaddr{$ipadentif})), AF_INET) if !$ipset{$ipadentif}; if (!defined $iphost{$ipadentif} || ($iphost{$ipadentif} eq '')){ $iphost{$ipadentif} = 'No name for IP'; } $ipset{$ipadentif} = 1; }); print STDERR "Got Addresses\n" if $DEBUG; print STDERR "Got IfTable\n" if $DEBUG; my(%sifdesc,%siftype,%sifspeed,%sifadminstatus,%sifoperstatus,%sciscodescr); ### May need the cisco IOS version number so we know which oid to use ### to get the cisco description. ### ### - mjd 2/5/98 (Mike Diehn) (mdiehn@mindspring.net) ### my ($cisco_ver, $cisco_descr_oid, @ciscodescr); if ( $ciscobox ) { ($cisco_ver) = ($sysDescr =~ m/Version\s+([\d\.]+)\(\d/o); $cisco_descr_oid = ($cisco_ver ge "11.2") ? "ifAlias" : "CiscolocIfDescr"; }$session->map_table ([[1,3,6,1,2,1,2,2,1,1], # ifIndex [1,3,6,1,2,1,2,2,1,2], # ifDescr [1,3,6,1,2,1,2,2,1,3], # ifType [1,3,6,1,2,1,2,2,1,5], # ifSpeed [1,3,6,1,2,1,2,2,1,7], # ifAdminStatus [1,3,6,1,2,1,2,2,1,8]], # ifOperStatussub ($@) { my ($rowindex,$index,$ifdescr,$iftype,$ifspeed,$ifadminstatus,$ifoperstatus) = @_; grep (defined $_ && ($_=pretty_print $_), ($index,$ifdescr,$iftype,$ifspeed,$ifadminstatus,$ifoperstatus)); $sifdesc{$index} = $ifdescr; $siftype{$index} = $iftype; $sifspeed{$index} = $ifspeed; $sifadminstatus{$index} = $ifadminstatus; $sifoperstatus{$index} = $ifoperstatus; if ($portmaster && $vendor) { # We can only approximate speeds # # so we think that ppp can do 76800 bit/s, and slip 38400. # (actualy, slip is a bit faster, but usualy users with newer modems # use ppp). Alternatively, you can set async speed to 115200 or # 230400 (the maximum speed supported by portmaster). # # But if the interface is ptpW (sync), max speed is 128000 # change it to your needs. On various Portmasters there are # various numbers of sync interfaces, so modify it. # # The most commonly used PM-2ER has only one sync. # # Paul Makeev (mac@redline.ru) # if ($siftype{$index} eq '23') { if ($sifdesc{$index} eq 'ptpW1') { $sifspeed{$index} = 128000; } else { $sifspeed{$index} = 76800; } } elsif ($siftype{$index} eq '28') { $sifspeed{$index} = 38400; } elsif ($siftype{$index} eq '6') { $sifspeed{$index} = 10000000; } } ### Move this section south so we know what type of ### circuit we're looking at before we retrieve ### the cisco interface alias. ### ### This whole cicso thing should be re-written, but since ### this script doesn't need to run quickly... ### ### - mjd 2/5/98 ### # Get the user configurable interface description entered in the config # if it's a cisco-box # if ($ciscobox && $vendor) { my ($enoid, @descr); $enoid = $cisco_descr_oid . "." . $index; if ( $cisco_ver ge "11.2" or $siftype{$index} != '32' ) { ### This is either not a frame-relay sub-interface or ### this router is running IOS 11.2+ and interface ### type won't matter. In either of these cases, it's ### ok to try getting the ifAlias or ciscoLocIfDesc. ### @descr = snmpget("$community\@$router", $enoid); } else { ### This is a frame-relay sub-interface *and* the router ### is running an IOS older than 11.2. Therefore, we can ### get neither ifAlias nor ciscoLocIfDesc. Do something ### useful. ### @descr = ("Cisco PVCs descriptions require IOS 11.2+."); } # end if else ### Put whatever I got into the array we'll use later to append the result ### of this operation onto the results from the ifDescr fetch. ### push @ciscodescr, shift @descr; } # end if ($cisco_box && $vendor) # especially since cisco does not return a if # descr for each interface it has ... ## JB 2/8/97 - sometimes IOS inserts E1 controllers in the standard-MIB ## interface table, but not in the local interface table. This puts the ## local interface description table out-of-sync. the following ## modification skips over E1 cards as interfaces. # ### I suspect that the mod I made above, to use the ifAlias ### oid if possible, may cause problems here. If it seems ### that your descriptions are out of sync, try commenting ### out the "if ( condition )" and it's closing right brace ### so that the "shift @ciscodescr" get executed for *all* ### iterations of this loop. ### ### - mjd 2/5/95 #### if ($ciscobox && $siftype{$index} != 18) { $sciscodescr{$index} = "<BR>" . (shift @ciscodescr) if @ciscodescr;# }}); my $index; print "#---------------------------------------------------------------\n";INTERFACE: foreach $index ( sort { $a <=> $b } keys %sifdesc) { my $c; my $speed = int($sifspeed{$index} / 8); # bits to byte my $speed_str=&fmi($speed); $name="$iphost{$index}"; $name = "$router.$index" if not $name or $name =~ /\s/; if (($sifadminstatus{$index} != 1)# this check added by Josh - don't query E1-stack controllers || ($siftype{$index} == 18) || ($siftype{$index} == 24) || ($speed == 0 ) || ($speed > 400 * 10**6) #speeds of 400 MByte/s are not realistic || ($sifoperstatus{$index} == 3)) { if(!$comments) { next INTERFACE ; } print <<ECHO;################ This Interface is one of the following######## - administratively not UP######## - it is in test mode######## - it is a softwareLoopback interface######## - has a unrealistic speed setting######## It is commented out for this reason.########ECHO $c="# "; }else { $c = ''; } $codesc = $sciscodescr{$index};my $coindex = $index;my $coSubdir = "";my $coTitle = ""; if ($codescr) { $codesc =~ s/ /-/g; NormaliseDescr(); $codesc =~ s/-+/-/g; $codesc =~ s/^-|-$//; $name = lc($codesc) if ($codesc =~ /.+/); } if ($ipindex) { $coindex = "/".$ipaddr{$index} if ($ipaddr{$index} =~ /.+/); } if ($subdir) { $coSubdir = "\n${c}Directory[$name]: $router"; } $coTitle = $sciscodescr{$index}; $coTitle =~ s/<BR>//; if (!$coTitle) { if (! $withnodescr) { next INTERFACE ; } $coTitle = "$sysName ($iphost{$index}): $sifdesc{$index}"; } if ($invertreg) { $coindex = "-".$coindex if ($coTitle =~ /$invertreg/x ) } elsif ($noinvertreg) { $coindex = "-".$coindex if ($coTitle !~ /$noinvertreg/x ) } if ($match) { next INTERFACE if ($coTitle !~ /$match/); } if ($nomatch) { next INTERFACE if ($coTitle =~ /$nomatch/); } print <<ECHO;${c}${c}Target[$name]: $coindex:$community\@$router # $index $coSubdir${c}MaxBytes[$name]: $speed${c}Title[$name]: $coTitle${c}PageTop[$name]: <H1>Traffic Analysis for $sifdesc{$index}${c} $sciscodescr{$index}</H1>ECHO print <<TABLE if ($withtables);${c} <TABLE>${c} <TR><TD>System:</TD><TD>$sysName in $sysLocation</TD></TR>${c} <TR><TD>Maintainer:</TD><TD>$sysContact</TD></TR>${c} <TR><TD>Interface:</TD><TD>$sifdesc{$index} ($index)</TD></TR>${c} <TR><TD>IP:</TD><TD>$iphost{$index} ($ipaddr{$index})</TD></TR>${c} <TR><TD>Max Speed:</TD>${c} <TD>$speed_str ($ifType_d{$siftype{$index}})</TD></TR>${c} </TABLE>TABLE print <<SEPA;${c}#---------------------------------------------------------------SEPA }} main;exit(0);sub fmi { my($number) = $_[0]; my(@short); @short = ("Bytes/s","kBytes/s","MBytes/s","GBytes/s"); my $digits=length("".$number); my $divm=0; while ($digits-$divm*3 > 4) { $divm++; } my $divnum = $number/10**($divm*3); return sprintf("%1.1f %s",$divnum,$short[$divm]);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -