顯示具有 ip 標籤的文章。 顯示所有文章
顯示具有 ip 標籤的文章。 顯示所有文章

2012年12月23日 星期日

Cisco Perl threads program to manage numeric Cisco equipments

Cisco Perl Telnet Script:

A single thread Perl program fetches Cisco routers/switches config or other info may take 2 seconds per equipment. If you have 1,000 Cisco routers/switches, it’ll take 2,000 seconds which will be 33+ mins. This Perl threads program will save tons of your time to gather info like within 10 seconds. Please enjoy!
1. Successful messages( scalar type ) are stored in hash of hash : $hostinfo{ “$hostname” }->{ “$cmd” }
2. Failed messages( scalar type ) are stored in hash of hash : $hosterrinfo{ “$hostname” }->{ “$cmd” }
#!/usr/bin/perl -w
# This perl script is main to be doing numeric cisco equipment management

use strict;
use threads;
use threads::shared;

my @hosts = ( 'host name or IP', 'host name or IP' );
my @threads = ();

# Shared data declaration

my @cmds :shared = ( 'sh geego', 'sh ver', 'sh clock', 'sh queueing', 'sh hosts' );
my $username :shared = 'username';  # cisco telnet username
my $passwd :shared = 'password';   # cisco telnet username
my $enable_passwd :shared = 'enable password';
my %hostinfo :shared = ();
my %hosterrinfo :shared = ();

foreach my $host ( @hosts )
{
$hostinfo{ "$host" } = &share( {} );
$hosterrinfo{ "$host" } = &share( {} );
push( @threads, threads->new( \&get_info, $host ) );
}
foreach ( @threads )
{
$_->join();
}

sub get_info
{
use Net::Telnet::Cisco;  #Special Perl Cisco Telnet module
my ( $hostname ) = @_;

my $cisco = Net::Telnet::Cisco->new( 'Host' => $hostname,
'Errmode'=> 'return' );  #Perl Cisco Telnet Object initialization
$cisco->login( Password => "$passwd" );
$cisco->ignore_warnings;

foreach my $cmd ( @cmds )
{
my @output = $cisco->cmd( "$cmd" );

if( $cisco->errmsg() )
{
$hosterrinfo{ $hostname }->{ $cmd } = $cisco->errmsg();
}
else
{
my $out = join( "", @output );
$hostinfo{ $hostname }->{ $cmd } = $out;
}
}
}

foreach my $host ( keys %hostinfo )
{
foreach ( keys %{$hostinfo{ $host }} )
{
print " $host => $_ => $hostinfo{ $host }->{ $_ }";
}
}

More technical tips see:http://www.geego.com/tech_support/new-tip-list

2012年4月6日 星期五

奇科電腦 使用GRE建立site-to-site VPN tunnel

<更多技術小秘訣請參考http://www.geego.com.tw/tech_support/new-tips>

為了方便企業在不同地理區域也能共同分享各分部的資源,企業總部與分部之間可以建立VPN通道達成資源分享的目的,本篇介紹以Cisco GRE(Generic Routing Encapsulation) 的方式來建立VPN通道

文件RFC2784(http://tools.ietf.org/html/rfc2784) 定義了GRE(Generic Routing Encapsulation)的規範,是一個簡單的IP封包封裝協定,GRE通道可以讓路由器連接兩個不同的區域網路達成一種VPN的效果

GRE tunnel
------------site A -- -- -- -- -- -- -- -- siteB-------------
59.12.30.9   211.22.33.99

================================================
Site A configuration:
#create gre tunnel
/sbin/ip tunnel add HQ_branch mode gre remote 211.22.33.99 \
local 59.12.30.9 ttl 255 dev eth0 key 1.2.3.4

# bring up gre tunnel interface
ip link set HQ_branch up

# assign gre tunnel ip
/sbin/ip addr add 10.1.255.1/32 peer 10.2.255.1/32 dev HQ_Branch
ifconfig HQ_Branch multicast
================================================
Site B configuration:

# add gre tunnel to hq
/sbin/ip tunnel add Branch_HQ mode gre remote 59.12.30.9 \
local 211.22.33.99 ttl 255 dev eth0 key 1.2.3.4

# bring up gre tunnel interface
/sbin/ip link set Branch_HQ up

# assign ip to gre tunnel
/sbin/ip addr add 10.2.255.1/32 peer 10.1.255.1/32 dev Branch_HQ
ifconfig Branch_HQ multicast
=================================================