⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netsh

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻
📖 第 1 页 / 共 2 页
字号:
	    }	    my $oldcount = 0;	    while($row = $sth->fetchrow_arrayref) {				if ($running_watch) {		    $newrow=[];		    my $count;		    for($count = 0; $count <= $#$row; $count++) {			if ($older_data &&			    $row->[$count] ne			    $older_data->[$oldcount][$count]) {			    if ($ansicolor) {				push @$newrow, new color_string($row->[$count],'red');			    } else {				push @$newrow,"$begin$row->[$count]$end";			    }			} else {			    push @$newrow,$row->[$count];			}			if ($running_watch == 1) {			    $old_data->[$oldcount][$count] = $row->[$count];			}		    }		    $oldcount++;		    $row = $newrow; 		}		# self printing;		if (ref($subfn) eq "CODE") {		    &$subfn($printfmt,@$row);		    next;		}		if ($opts{'t'}) {		    if ($opts{'d'} eq 'xml') {			print "  <row>\n";			for(my $xx = 0; $xx < $#{$sth->{NAME}}; $xx++) {			    print "    <$sth->{NAME}[$xx]>$row->[$xx]</$sth->{NAME}[$xx]>\n";			}			print "  </row>\n";		    } elsif ($opts{'d'} eq 'xmlshort') {			print "  <row ";			for(my $xx = 0; $xx < $#{$sth->{NAME}}; $xx++) {			    print " $sth->{NAME}[$xx]=\"$row->[$xx]\"";			}			print "/>\n";		    } else {			print join($opts{'d'},@$row),"\n";		    }		} elsif (!$table) {		    $table = Text::FormatTable->new('|r' x ($#$row+1) . "|");		    $table->rule('-');		    $table->head(@{$sth->{NAME}});		    $table->rule('-');		    $table->row(@$row);		} else {		    $table->row(@$row);		}	    }	    if ($table) {		$table->rule('-');		print $table->render();	    }	}	$sth->finish();	return;    }    # retrieve just one variable and display it    if ($stmt =~ /^(get|)\s*([^\s]+)\s*[^=]/) {	my $sess = make_session();	if ($sess) {	    my @results = split(/[,\s]+/,$stmt);	    my $resultsv = new SNMP::VarList();	    # expression stolen from the main perl SNMP module	    map {  my ($tag, $iid) = 		       (/^((?:\.\d+)+|(?:\w+(?:\-*\w+)+))\.?(.*)$/);		   push @$resultsv, [$tag, $iid] } @results;	    $sess->get($resultsv)  || 		print STDERR "Error: $sess->{ErrorNum} $sess->{ErrString}\n";  	    @results = ();	    map { push @results, $_->[2] } @$resultsv;	    if (ref($subfn) eq "CODE") {		&$subfn($printfmt,@results);	    } else {		print join(" ", @results),"\n";	    }	} else {	    print STDERR "could not establish a SNMP session to $host\n";	}	return;    }    # set something    if ($stmt =~ /^(set|)\s*([^\s]+)\s=\s(.*)$/) {	my $sess = make_session();	if ($sess) {	    $sess->set([$2,undef,$1]) || 		print STDERR "opps: $sess->{ErrorNum} $sess->{ErrString}\n";	} else {	    print STDERR "could not establish a SNMP session to $host\n";	}	return;    }}sub auto_snmp {    my $node = $SNMP::MIB{$_[0]};#    print STDERR "netsh::fetch_snmp $_[0] $node->{label}\n";    my $indexes = $node->{parent}{indexes};    if ($#$indexes > -1) {#	print STDERR "column\n";	# table     } else {	# scalar	if (exists($_[1])) {	    my $sess = make_session();	    my $val = $sess->set([$_[0],0,$_[1]]) || return;#	    print STDERR "scalar set: $val\n";	    return $val;	} else {	    my $sess = make_session();	    my $val = $sess->get([$_[0],0]);#	    print STDERR "scalar get: $val\n";	    return $val;	}    }}sub AUTOLOAD {    my $nodename = $AUTOLOAD;    $nodename =~ s/.*:://;    print STDERR "netsh::AUTOLOAD $AUTOLOAD $nodename\n";    if ($SNMP::MIB{$nodename}) {	eval << "END";        sub $AUTOLOAD {	    auto_snmp($nodename, \@_);	}END	goto &$AUTOLOAD;    }    print STDERR join(",",@_),"\n";}sub my_printf {    # drop quotes    my $fmt = shift;    $fmt = eval $fmt;    map { if (ref($_) eq "color_string") { $_->colorize_next(); } } @_;    printf($fmt, @_);}sub display_alias {    my $name = shift;    if (exists $aliases{$name}{'definition'}) {	if (ref($aliases{$name}{'definition'}) eq "ARRAY") {	    print "alias $name {\n";	    map { print "  $_\n"; } @{$aliases{$name}{'definition'}};	    print "}\n";	} else {	    print "alias $name $aliases{$name}{'definition'}\n";	}    } else {	print "no alias defined for \"$name\"\n";    }}sub make_session {    if (!$sess) {	$sess = new SNMP::Session(@sessparms);    }    return $sess;}sub usage {    print STDERR "$0 [ARGUMENTS] HOSTNAME [SQL_COMMAND]   $0 implements a simple SQL shell which maps onto SNMP.  All  statements issued within the shell are converted to SNMP requests and  sent to HOSTNAME and the results displayed in a nice table output  format if the Text::FormatTable module is available.  If SQL_COMMAND  is given on the command line, then it's interpreted and control is  returned to the caller.  If not, an interactive prompt is given where  multiple commands can be issued.ARGUMENTS may include:  -t         delimiter separated output, don't print pretty tables.  -d DELIM   use DELIM as the delimiter.  A tab is the default delimiter.             'xml' is a special delimiter to produce xml output.ARGUMENTS also may include the following.  See the net-snmp snmpcmdmanual page for details on what they mean:  -v VERSION        (default: 1)  -t TIMEOUT  -r RETRIES  -p PORT  -c COMMUNITY  -a AUTHPROTOCOL   (default: MD5)  -x PRIVPROTOCOL   (default: DES)  -A AUTHPASS  -X PRIVPASS  -l SECURITY_LEVEL (default: authNoPriv)  ";    exit;}__END__=head1 NAMEnetsh - A shell environment for interacting with networking devices=head1 SYNOPSISnetsh [(subset of) snmpcmd arguments] hostname[,hostname...] [command]=head1 OPTIONAL PERL MODULESThere are some optional perl modules which make using the shell nicerin general.  These modules are:  Text::FormatTable  Term::ReadLine::Gnu or Term::ReadLine::Perl  Term::ANSIColorYou can install these by running [as root]:  perl -MCPAN -e shell  cpan> install Text::FormatTable  ...It is B<strongly> recommend you at least install the Text::FormatTablemodule, and if you like command line editing one of the two extraTerm::ReadLine modules (Gnu being the better of the two).=head1 DESCRIPTIONThe netsh script provides an interactive, console-like environmentsuitable for monitoring and manipulating data within networkingdevices.  The environment is highly extensible through commandaliases and easy-to-use SQL-like queries.It is implemented on top of the SNMP protocol using the net-snmppackage and perl.  See the snmpcmd and snmp.conf manual pages fordetails on configuring net-snmp for authentication information forthe networking devices you wish to access.=head1 ABOUT THE EXAMLPES IN THIS DOCUMENTAll the examples in this document are exact cut-n-pastes from theinside of the netsh shell.  This includes the "netsh> " prompt andpossibly other prompts as well.=head1 COMMANDSThe following is a list of the basic core commands supported bynetsh.  Many default aliases are also supplied, some of which arelisted in the next section.  At the command prompt type "alias" fora full list of all the aliases and their definitions.=over=item show columns from TABLE=item select ... =item update ...=item insert ...=item delete ...netsh supports the standard sql-like language queries of snmp tables.These are implemented via the SQL::Statement parser, so any form ofexpression it accepts netsh will accept as well.Examples:  netsh> show columns from ifTable  +-----------------+  |           Column|  +-----------------+  |          ifIndex|  ...  netsh> select * from ifTable  ... [output not shown]  netsh> select tcpConnState, tcpConnRemotelAddress from tcpConnTable where tcpConnState = established  ... [output not shown]  netsh> update ifTable set ifAdminStatus = up where ifOperStatus = down  ... [output not shown]=item SNMPOBJECTSimple lists of objects may be given which will directly request oroperate on those objects.  See printf below for controlling theformatting of resultsExamples:  netsh> sysContact.0, sysLocation.0  hardaker@somewhere.net my location  netsh> sysContact.0 = my new contact information=item alias my_command some other commandor=backalias my_many_commands {  command1  command2  prompt NUMBER question}=over=itemYou can create aliases of your frequently used commands by aliasingthem to an easy to remember name.  \N parameters in the definedcommand will be replaced by the positional argument of options passedto the alias name.For multi-line defined aliases, optional prompts may be given torequest information from the user when the NUMBERth argument is notgiven to the alias.  If it is not given, the prompt will be printedand the user will be asked to input a value for it.  This allows theeasy definition of interactive commands.  The value will be insertedin alias parts containing \N substitution requests.  netsh> alias interfaces select ifDescr from ifTable  netsh> interfaces  +-------+  |ifDescr|  +-------+  |     lo|  |   eth0|  +-------+  netsh> alias interface select ifDescr, ifSpeed from ifTable where ifDescr = '\1'  netsh> interface eth0  +-------+--------+  |ifDescr| ifSpeed|  +-------+--------+  |   eth0|10000000|  +-------+--------+=item printf FORMATSTRING COMMANDAllows B<careful> formatting of results returned by the commands.Example:  netsh> alias interface {  define interface> printf "interface %s is running at %d Mb/s\n" select ifDescr, ifSpeed from ifTable where ifDescr = '\1'  define interface> prompt 1 Enter the interface to describe:  define interface> }  netsh> interface  Enter the interface to describe: eth0  interface eth0 is running at 10000000 Mb/sTo list the definition of an already defined command, simply excludethe definition and netsh will report the definition to you:  netsh> alias interface  alias interface {    printf "interface %s is running at %d Mb/s\n" select ifDescr, ifSpeed from ifTable where ifDescr = '\1'    prompt 1 Enter the interface to describe:  }To list all the aliases defined in the system, just type "alias" by itself.=item watch [TIME] COMMANDContinually watches the results of the COMMAND being run, which is runevery TIME seconds.  For select statements, it will attempt to markthe changing values from one screen to the next by surrounding themwith "*"s or color (assuming you have the Term::ANSIColor perl moduleinstalled) for easy picking out on the screen.=item rehashRe-load the alias definitions files in the common directory, aswell as those files found in $HOME/.snmp/netsh.=item source FILEloads definitons and commands from FILE into the running environment.=back=head1 FILESBy default, netsh will source all the definition files it can find.It does this by first reading everything in/usr/local/share/snmp/netsh/* and then reading everything in$HOME/.snmp/netsh/*.  Everything contained in these files arecommands, but most frequently they entirely consist of aliasesdefinitions.=head1 AUTHORbugs, comments, questions to net-snmp-users@lists.sourceforge.net=head1 Copyright     Copyright (c) 2002 Networks Associates Technology, Inc. All     rights reserved.  This program is free software; you can     redistribute it and/or modify it under the same terms as Perl     itself.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -