$user="myname"; $pass="mypass"; @ip = split( /\./, $IPNumber ); if ( $ip[0] == 110 ) { $rtrIP = "10.10.10.1"; } else if ( $ip[0] == 120 ) { $rtrIP = "10.20.20.1"; } else { die( "not in my range" ); } ($Core) = &SSHconnect( $rtrIP, $user, $pass ); @Output = $Core->capture( "show ip route $IPNumber" ) or die( " command failed: " . ($! >> 8) ); ($Core2) = &SSHconnect( $rtrIP, $user, $pass ); @Output2 = $Core2->capture( "show run | include hostname" ) or die( " command failed: " . ($! >> 8) ); foreach $Line ( @Output || @Output2 ) { if ( $Line =~ m/^Routing entry for / ) { @Data = split( ' ', $Line ); $Subnet = $Data[ 3 ] ; last ; } if ( $Line =~ m/^hostname / ) { @Data2 = split( ' ', $Line ); $Rname = $Data[ 2 ] ; last ; } } @network = split( /\./, $Subnet ); $rIP = join( '.', $network[0], $network[1], $network[2], '1' );