All pastes #35378 Raw Edit

Perl

public text v1 · immutable
#35378 ·published 2005-12-31 13:34 UTC
rendered paste body
#!/usr/bin/perl# by Ricardo Galli (gallir at uib dot es)# This software is licensed under the GNU General Public Licenseuse strict;use Net::Telnet;if (scalar @ARGV < 2) {    &usage;}my $upload = shift;my $download = shift;my $addr = "127.0.0.1";my $port = 4000;my $prompt = '/> $/';my $telnet;my %options;$telnet = new Net::Telnet ( Host => $addr, Port => $port,			    Prompt => $prompt) or die "Error opening connection";$telnet->waitfor($prompt);&get_options;print "Old: upload=$options{max_hard_upload_rate}";print " download=$options{max_hard_download_rate}\n";&set_option("max_hard_upload_rate", $upload);&set_option("max_hard_download_rate", $download);&get_options;print "New: upload=$options{max_hard_upload_rate}";print " download=$options{max_hard_download_rate} \n";# Disconnect$telnet->print('q');sub get_options {    my ($name, $value);    my @output = $telnet->cmd('vo');    foreach $_ (@output) {	chomp;	# Clean ANSI escape sequences	s/\x1b\x5b[^\x6d]+\x6d//g;	if( ($name, $value) = /([\w\.]+)\W+=\W+([\w\.]+)/) {	    $options{$name} = $value;	}    }}sub set_option {    my ($name, $value) = @_;    $telnet->cmd("set $name $value");}sub usage {    die "Usage:\n\t$0 upload download\n\n";}