Setting up a gateway on Cisco Routers: Difference between revisions

From 44Net Wiki
Jump to navigation Jump to search
4Z4ZQ (talk | contribs)
No edit summary
4Z4ZQ (talk | contribs)
No edit summary
Line 430: Line 430:
The VBS Script is enclosed here
The VBS Script is enclosed here


' encap2cisco.vbs, v0.2
  ' encap2cisco.vbs, v0.2
' Scripts to convert encap.txt file in Cisco IOS configuration commands
' Scripts to convert encap.txt file in Cisco IOS configuration commands
' to create Tunnel interfaces and routing to "gateway" traffic for ampr.org.
  ' to create Tunnel interfaces and routing to "gateway" traffic for ampr.org.
' For each gateways the script creates a Tunnel interface (starting from # 1001)
' For each gateways the script creates a Tunnel interface (starting from # 1001)
' with routing and other detailed cfg commands.
' with routing and other detailed cfg commands.
' Before to start keep in mind:
' Before to start keep in mind:
' - Tunnel interfaces are unnumbered of interface declared in MyLoopback variable
' - Tunnel interfaces are unnumbered of interface declared in MyLoopback variable
' - Public IP address of local gateway is declared in MyPublic variable   
' - Public IP address of local gateway is declared in MyPublic variable   
' - Output is to console (use redirecting to save it to a file).
' - Output is to console (use redirecting to save it to a file).
' - Running from command line example: cscript encap2cisco.vbs > cisco.cfg
' - Running from command line example: cscript encap2cisco.vbs > cisco.cfg
'
' Tested on Cisco IOS 12.3(22) version
'
' Made by IW0SAB Renzo, free to use and to adapt to specific usages.
' Thanks to IW0RZM Andrea for script suggestions.
' CisarNet Project of Italian Radio Ham Association CISAR
'
' Static entry for Master Tunnel to ampr.org
'!
'interface Tunnel44
'description Tunnel vs. ampr.org (Master tunnel: 44.0.0.0/8)
'! Loopback440 is my main 44.208.0.1 interface
'ip unnumbered Loopback440
'! Loopback1 is my public IP address
'tunnel source Loopback1
'! 160.228.66.251 is main ampr.org tunnel gateway (amprgw.sysnet.ucsd.edu)
'tunnel destination 169.228.66.251
'tunnel mode ipip
'ip route 44.0.0.0 255.0.0.0 Tunnel44
'
' Gubbio (ITALY), 31.10.2011 - Ver 0.2
'
'
' Tested on Cisco IOS 12.3(22) version
'On Error Resume Next
'
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Made by IW0SAB Renzo, free to use and to adapt to specific usages.
Set objFile = objFSO.OpenTextFile("encap.txt", ForReading)
' Thanks to IW0RZM Andrea for script suggestions.
Const ForReading = 1
' CisarNet Project of Italian Radio Ham Association CISAR
Dim arrFileLines()
'
Dim Net, Mask, Gw, Tun, MyNets, MyLoopback, MyPublic, MyCredits
' Static entry for Master Tunnel to ampr.org
MyNets = Array("44.208/16", "44.134.226/24", "44.134.227/24", "44.134.228/24")
'!
MyPublic = "Loopback1"
'interface Tunnel44
MyLoopback = "Loopback440"
'description Tunnel vs. ampr.org (Master tunnel: 44.0.0.0/8)
MyCredits = "encap2cisco v0.2 by IW0SAB Renzo"
'! Loopback440 is my main 44.208.0.1 interface
i = 0
'ip unnumbered Loopback440
Tun = 1000
'! Loopback1 is my public IP address
line = 0
'tunnel source Loopback1
'
'! 160.228.66.251 is main ampr.org tunnel gateway (amprgw.sysnet.ucsd.edu)
' Reading encap.txt file in memory array
'tunnel destination 169.228.66.251
'
'tunnel mode ipip
Do Until objFile.AtEndOfStream
'ip route 44.0.0.0 255.0.0.0 Tunnel44
Redim Preserve arrFileLines(i)
'
arrFileLines(i) = objFile.ReadLine
' Gubbio (ITALY), 31.10.2011 - Ver 0.2
i = i + 1
'
Loop
'On Error Resume Next
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
'
Set objFile = objFSO.OpenTextFile("encap.txt", ForReading)
'Process all encap.txt lines
Const ForReading = 1
'
Dim arrFileLines()
WScript.Echo "!"
Dim Net, Mask, Gw, Tun, MyNets, MyLoopback, MyPublic, MyCredits
WScript.Echo "! Begin of Cisco IOS configuration file generated with " & MyCredits & "("   & Date & " " & Time & ")"
MyNets = Array("44.208/16", "44.134.226/24", "44.134.227/24", "44.134.228/24")
For Each strLine in arrFileLines
MyPublic = "Loopback1"
MyLoopback = "Loopback440"
MyCredits = "encap2cisco v0.2 by IW0SAB Renzo"
i = 0
Tun = 1000
line = 0
'
' Reading encap.txt file in memory array
'
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'
'Process all encap.txt lines
'
WScript.Echo "!"
WScript.Echo "! Begin of Cisco IOS configuration file generated with " & MyCredits & " (" & Date & " " & Time & ")"
For Each strLine in arrFileLines
x = Split(strLine, " ")
x = Split(strLine, " ")
line = line + 1
line = line + 1
Line 507: Line 507:
end if
end if
'
'
' If I need I process this line of encap.txt and create tunnel interfaces for ipip gateway
' If I need I process this line of encap.txt and create tunnel interfaces for ipip
 
gateway
'
'
If SkipLine = 0 Then
If SkipLine = 0 Then
Line 536: Line 538:
WScript.Echo "tunnel destination " & Gw
WScript.Echo "tunnel destination " & Gw
WScript.Echo "tunnel mode ipip"
WScript.Echo "tunnel mode ipip"
WScript.Echo "ip route " & Net & " " & Mask & " Tunnel " & Tun & " 200" ' Route Weight is high to be safe evolving to dynamic routing
WScript.Echo "ip route " & Net & " " & Mask & " Tunnel " & Tun & " 200" '
 
Route Weight is high to be safe evolving to dynamic routing
'
'
End If
End If
Next
Next
WScript.Echo "!"
WScript.Echo "!"
WScript.Echo "! End of configuration file generated with " & MyCredits
WScript.Echo "! End of configuration file generated with " & MyCredits
'
'
' Finished
' Finished
'
'
'=====================================================
'=====================================================
'
'
' Function to extract subnet network from line
' Function to extract subnet network from line
'
'
Function MyNet(b)
Function MyNet(b)
' b= "1.2.3.4/24"
' b= "1.2.3.4/24"
' Wscript.Echo "MyNet b:" & b & " - " & InStr(b,"/")
' Wscript.Echo "MyNet b:" & b & " - " & InStr(b,"/")
if InStr(b,"/") <= 0 Then
if InStr(b,"/") <= 0 Then
MyNet = b
MyNet = b
Line 571: Line 575:
End Function
End Function
'
'
' Function to extract subnet mask from line
' Function to extract subnet mask from line
'
'
Function MyMask(c)
Function MyMask(c)
' c = "1.2.3.4/24"
' c = "1.2.3.4/24"
Num = Right(c, Len(c) - InStr(c, "/"))
Num = Right(c, Len(c) - InStr(c, "/"))
Select Case Num
Select Case Num
Line 634: Line 638:
End Select  
End Select  
End Function
End Function

Revision as of 21:10, 1 March 2016

You can setup gateway on Cisco routers

Cisco support IPIP tunneling and that's what needed

First of all you must have a Cisco Router (preferred from series 2600 and above)

Preferred with two Ethernet cards (but can be done also with one Ethernet card)

I will give example of one Ethernet card

You have to assign the router Ethernet card the Commercial IP

The command is :

int eth0  ip add <and here you give the ip of the commercial ip the router sit on >
(it can be also IP of a network the router sit on  (as long as  this IP is accessible 
to the outside world))> <The NetMask of the network>

Then you have to assign the 44 Net IP

The command for router with 0ne ethernet card is:

int eth0  ip add <the AMPR IP > <the netmask of the network > secondary
 

Now you have to add some tunneling command to redirect your outgoing traffic (via tunnel) to the main AMPRNET router , you do it because every ISP block outgoing IP's which is not a part of his network (and 44 net is not belong to any ISP) so in order to allow the 44 Net Packet to gain access to the outside world you need to do a tunnel to the AMPR.ORG Router also to the outgoing traffic (traffic that intend to reach the internet (all other IP's that are not part of the 44 NET))

To open a tunnel command you have to put the tunnel Source address (from where the tunnel is established) and to where the tunnel establish to (tunnel destination) it is a few commands here they are

interface tunnel0
tunnel source <here you put the router commercial IP>
tunnel destination <here you put  the AMPR.ORG main tunnel router IP>
tunnel mode ipip   (this command is to tell the tunnel (cisco support lot of tunneling types) which  mode to use)

In addition you must tell the router to pass all the outgoing 44 Net Traffic to the tunnel interface and not to route it just like that to the Internet (because as explained they will be probably blocked by the closest ISP you are connecting to )

The command to do it is

ip route 0.0.0.0 0.0.0.0 Tunnel0 <the ip address of the AMPR.ORG main tunnel router >

(0.0.0.0 0.0.0.0 mean "everything") (will be explained latter)

Another important command is a command to let the traffic from the router to the main ampr.org router to pass their IP not via a tunnel (this important to establish tunnel)

This command is more specific then the "everything" route command described before and say to the router pass the traffic belong to the other side of the tunnel

The Command is :

ip route <the ampr.org main tunnel IP > 255.255.255.255 Ethernet0 <your  router commercial IP>

This are the minimum Commands to be able to route your inside 44 Net ip to the outside world (but not to any other 44 net networks worldwide)

In order to route your traffic to other 44 net gateways you need to build a tunnel interface to every gateway (unlike JNOS that one tunnel deal with all tunnels) and the tunnel have to have a tunnel source tunnel destination (as explained above ) and tunnel mode

In addition two route lines have to be added

One is route command to route the specific 44 network of the gateway this tunnel deal into this tunnel

And another is to allow the tunnel traffic to go thorough the internet

Enclosed is example from router that is doing tunnel to the main AMPR router and to one gateway somewhere in the world

The tunnel0 interface is the Main AMPR.ORG router and the tunnel with 741916672 is one tunnel to a gateway

The section of tunnel74xxx have to duplicated to every 44 net gateway (of course with the corresponding ip of the specific gateway) (currently about 400 times)

Later on we will deal of how to create these tunnels lines configuration using a script that takes the info from the ENCAP.TXT file and convert it to Cisco config


interface Tunnel0
ip unnumbered Ethernet0
no ip directed-broadcast
tunnel source Ethernet0
tunnel destination 169.228.66.251
tunnel mode ipip
!
interface Tunnel741916672
description Link to 44.56.192.0
ip unnumbered Ethernet0
ip access-group acl_44 in
no ip directed-broadcast
tunnel source 10.0.0.180
tunnel destination 24.229.88.253
tunnel mode ipip
interface Ethernet0
description connected to EthernetLAN_HAIFA
ip address 44.138.1.1 255.255.255.0 secondary
ip address 10.0.0.180 255.255.255.0
no ip directed-broadcast
ip classless
ip route 0.0.0.0 0.0.0.0 Tunnel0 169.228.66.251
ip route 169.228.66.251 255.255.255.255 Ethernet0 10.0.0.138
ip route 44.56.192.0 255.255.255.0 Tunnel741916672
ip route 24.229.88.253 255.255.255.255 Ethernet0 10.0.0.138

Making the roue commands automaticly

Because the route info of the gateways (the encap file) changes periodically mainly because alot of gateway sit on dynamic ip

and because the tunnel ip as a result change you may loose the tunnel to these gateways

In order to be "updated" it is needed to take the new encap file periodically and put it into the cisco router

Because the encap file lines are not a format of commands that Cisco "understand" a fomat conversion need to be made in order to convert route info in the encap file to commands that cisco can "understand"

So a Script that take the encap file and make a new file of Cisco commands must be run

There are two scripts that do it available one is Perl and other is VBS

The example will give the results of the Perl Script

The Perl Script for the Cisco enclosed

#!/usr/bin/perl
  1. encapconvert.pl V0.1 10-31-12
  2. Script created by Jason Begley KY9J ky9j.com ky9j@arrl.net
  3. This script is used for converting the encap.txt file from the AMPR net
  4. into a loadable config file for use on cisco routers. It is advised to use
  5. this on a 2600 or better router due to interface limits.

my ($line); my %nets = (); my $net = undef; my $mask = undef;

  1. Below are user defined varibles

my $loop = "Ethernet0"; #LOOPBACK INT CHANGE IF ALREADY IN USE my $outip = "10.0.0.180"; #YOUR PUBLIC IP ADDRESS my $loopip = "44.138.1.1"; #YOUR AMPR IP ADDRESS

  1. EO user defined varibles


my $file = $ARGV[0]; my $debug = $ARGV[1]; if(!$file) { usage(); exit; } if($file =~ /--help/) { usage(); exit; }

open (MYFILE, '>cisco-config.txt');
print MYFILE "!\ninterface $loop\nip address $loopip 255.255.255.255\n!\n";
close (MYFILE);

open(ENCAP, $file); @line = <ENCAP>; close (ENCAP); @line = grep (!/^\s*$/,@line); @line = grep (!/^#/,@line); chomp(@line);

foreach $line(@line) {

       $n1 = $n2 = $n3 = $n4 = undef;
       @ln = (split(/ +/, $line));
       ($n, $s) = (split(/\//, $ln[2]));
       ($n1, $n2, $n3, $n4) = split(/\./, $n);
       $gw = $ln[4];
       $gw =~ s/\s*$//;

       if      ($n1 == )  {  $n1='0'};
       if      ($n2 == )  {  $n2='0'};
       if      ($n3 == )  {  $n3='0'};
       if      ($n4 == )  {  $n4='0'};
       if ($s == '1')  { $mask='128.0.0.0'};
       if ($s == '2')  { $mask='192.0.0.0'};
       if ($s == '3')  { $mask='224.0.0.0'};
       if ($s == '4')  { $mask='240.0.0.0'};
       if ($s == '5')  { $mask='248.0.0.0'};
       if ($s == '6')  { $mask='252.0.0.0'};
       if ($s == '7')  { $mask='254.0.0.0'};
       if ($s == '8')  { $mask='255.0.0.0'};
       if ($s == '9')  { $mask='255.128.0.0'};
       if ($s == '10') { $mask='255.192.0.0'};
       if ($s == '11') { $mask='255.224.0.0'};
       if ($s == '12') { $mask='255.240.0.0'};
       if ($s == '13') { $mask='255.248.0.0'};
       if ($s == '14') { $mask='255.252.0.0'};
       if ($s == '15') { $mask='255.254.0.0'};
       if ($s == '16') { $mask='255.255.0.0'};
       if ($s == '17') { $mask='255.255.128.0'};
       if ($s == '18') { $mask='255.255.192.0'};
       if ($s == '19') { $mask='255.255.224.0'};
       if ($s == '20') { $mask='255.255.240.0'};
       if ($s == '21') { $mask='255.255.248.0'};
       if ($s == '22') { $mask='255.255.252.0'};
       if ($s == '23') { $mask='255.255.254.0'};
       if ($s == '24') { $mask='255.255.255.0'};
       if ($s == '25') { $mask='255.255.255.128'};
       if ($s == '26') { $mask='255.255.255.192'};
       if ($s == '27') { $mask='255.255.255.224'};
       if ($s == '28') { $mask='255.255.255.240'};
       if ($s == '29') { $mask='255.255.255.248'};
       if ($s == '30') { $mask='255.255.255.252'};
       if ($s == '31') { $mask='255.255.255.254'};
       if ($s == '32') { $mask='255.255.255.255'};
       if ($s == )   { $mask='255.255.255.255'};
 $net = "$n1.$n2.$n3.$n4";
 $ifid = cipdec(1, $net);
 $wmask = do_subtract($mask);
 print "*ip info*\n";
 print "NET:$n\nBITS:$s MASK:$mask-$wmask\nGW:$gw\nIF:$ifid\n\n";
 open (MYFILE, '>>cisco-config.txt');

if ($debug != NULL) {

 print "LINE:$line";
 print "\n!\n";
 print "interface tunnel $ifid\n";
 print "description Link to $net\n";
 print "ip unnumbered $loop\n";
 print "tunnel source $outip\n";
 print "tunnel destination $gw\n";
 print "tunnel mode ipip\n!\n";

}

if ($gw != $outip) {

 print MYFILE "!\n";
 print MYFILE "interface tunnel $ifid\n";
 print MYFILE "description Link to $net\n";
 print MYFILE "ip unnumbered $loop\n";
 print MYFILE "tunnel source $outip\n";
 print MYFILE "tunnel destination $gw\n";
 print MYFILE "ip tcp adjust-mss 1436\n";
 print MYFILE "ip access-group acl_44 in\n!\n";
 print MYFILE "tunnel mode ipip\n!\n";
 print MYFILE "ip route $net $mask tunnel$ifid\n!\n";

}

 print MYFILE "ip route  $gw 255.255.255.255 Eth0 10.0.0.138\n";

}

print MYFILE "!\nend\n!\n";
close (MYFILE);

sub usage

 {
 print << "EOT";
      • This script is for creating a loadable config (copy tftp run) for cisco routers ***
      • Please note that this was tested to work on 2651XM or better, expect poor resp- ***
      • -onse on smaller/slower platforms. ***
      • Edit this file and change varibles as noted to your values. ***
      • File \"cisco-config.txt\" will be generated in this directory for tftp upload ***
      • Run as follows: ***
      • perl encapconvert.pl encap.txt ***

EOT

 }

  1. Sub cipdec
  2. USAGE: For converting IP to DEC values and reverse
  3. my ($err, $ret) = cipdec(1, $ip); #1 =from ip to dec, 2 = from dec to ip
  4. if($err != 0) { print "MAIN: ERR ON \"$ret\"\n"; next; }

sub cipdec

 {
 my $debug = 0;
 my (@oct, $opt, $var, $err, $ret, $errmsg);
 my ($oct1, $oct2, $oct3, $oct4);
 my ($dec1, $dec2, $dec3);
 $opt = shift(@_); #1 =from ip to dec, 2 = from dec to ip
 $var = shift(@_); # IP or a DEC 
 $err = 0;
 $ret = 0;
 if($debug == 1) 
   { 
   print "SUB TEST: OPT=\"$opt\"\n";
   print "SUB TEST: VAR=\"$var\"\n";
   }
 if($opt == 1) #1 =from ip to dec
   {
   my $ip = $var;
   if(!($ip) || ($ip eq "") || !($ip =~ /\./))
     {
     if($debug == 1) { print "NO . in IP.. Next\n"; }
     $err = 1;
     $ret = "ERR: IP WITH NO \".\"";
     return($err, $ret);
     }
   @oct = split(/\./, $ip);
   my $numoct = @oct;
   if($numoct != 4)
     {
     if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; }
     $err = 1;
     $ret = "ERR: OCT CT \"$ip\"";
     return($err, $ret);
     }
   foreach my $val (@oct)
     {
     if(!(defined $val) || ($val eq "") || ($val =~ /\D/) || ($val > 255) || ($val < 0))
       { 
       if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; }
       $err = 1;
       $ret = "ERR: OCT SIZE \"$ip:$val\"";
       return($err, $ret);
       } # EO IF oct container
     } #EO FOREACH OCT
   $ret += ($oct[0] * (256**3)); #Convert 1st octet to decimal and add
   $ret += ($oct[1] * (256**2)); #Convert 2nd octet to decimal and add
   $ret += $oct[2] * 256; #Convert 3rd octet to decimal and add
   $ret += $oct[3]; #Add the 4th octet to decimal
   if(($ret < 0) || ($ret > 4294967296)) #0.0.0.0 or 255.255.255.255 = Err
     {
     if($debug == 1) { print "--INVALID IP: \"$ip\"\n"; }
     $err = 1;
     $ret = "ERR: DEC SIZE \"$ip\"";
     return($err, $ret);
     } #EO DEC Size
   
   return($err, $ret);
   } #EO OPT == 1


 if($opt == 2) #1 = dec to ip
   {
   $oct1 = 0; $oct2 = 0; $oct3 = 0; $oct4 = 0;
   my $dec = $var;
   if($debug == 1) { print "SUB TEST: DEC=\"$dec\"\n"; }
   
   if(!(defined $dec) || ($dec eq "") || ($dec < 1) || ($dec > 4294967295)) #0.0.0.0 or 255.255.255.255 = Err
     {
     if($debug == 1) { print "--INVALID DEC: \"$dec\"\n"; }
     $err = 1;
     $ret = "ERR: DEC SIZE \"$dec\"";
     return($err, $ret);
     } #EO DEC Size   
  
   if($dec >= 256**3)
     {
     $oct1 = ($dec / 256**3);
     my @num = split(/\./, $oct1);
     $oct1 = $num[0];
     if($debug == 1) { print "OCT1: \"$oct1\"\n"; }
     $dec1 = ($oct1 * 256**3);
     $dec = $dec - $dec1;
     }
   if($dec >= 256**2)
     {
     $oct2 = ($dec / 256**2);
     my @num = split(/\./, $oct2);
     $oct2 = $num[0];
     if($debug == 1) { print "OCT2: \"$oct2\"\n"; }
     $dec2 = ($oct2 * 256**2);
     $dec = $dec - $dec2;
     }
   if($dec >= 256)
     {
     $oct3 = ($dec / 256);
     my @num = split(/\./, $oct3);
     $oct3 = $num[0];
     if($debug == 1) { print "OCT3: \"$oct3\"\n"; }
     $dec3 = $oct3 * 256;
     $dec = $dec - $dec3;
     }
 
   $oct4 = $dec;  
   if($debug == 1) { print "OCT4: \"$oct4\"\n"; }
   $ret = "$oct1.$oct2.$oct3.$oct4";
   return($err, $ret);
   } #EO If $opt == 2  
 
 $err = 1;
 $ret = "I'm lost and sent to leftovers";  
 return($err, $ret);
 }
                                      1. EO SUB CIPDEC#################################
      1. wildcard sub ###

sub do_subtract( ) {

 local($ip) = @_;
 # break up the bytes of the incoming IP address
 $_ = $ip;
 ($a, $b, $c, $d) = split(/\./);
 if ($a > 255 || $b > 255 || $c > 255 || $d > 255 || /[^0-9.]/) {
    print "invalid input mask or wildcard\n";
    exit(  );
 }
 $a = 255 - $a;
 $b = 255 - $b;
 $c = 255 - $c;
 $d = 255 - $d;
 return ($a . "." . $b . "." . $c . "." . $d);

}

      1. EO wildcard sub ###

Before you run the script make sure to take the line of your gateway from the encap file

The result of the script is set of commands that look like that

interface tunnel 748306432
description Link to 44.154.64.0
ip unnumbered Ethernet0
tunnel source 10.0.0.180
tunnel destination 79.107.164.191
ip tcp adjust-mss 1436
ip access-group acl_44 in
!
tunnel mode ipip
!
ip route 44.154.64.0 255.255.255.0 tunnel748306432
!
ip route  79.107.164.191 255.255.255.255 Ethernet0 10.0.0.138
!

This section return (with different IP , destination and route IPs's ) as the amount of lines in the encap file

When the file is ready (after running the perl script) you can copy it with editor and send it to the cisco or by terminal (with the config t command) or by TFTP

The Encap file can be taken automatically from the Portal using the API and you can push the commands to the cisco (after the encap convert to cisco commands after running perl) with TFTP

So with a small software work the whole procedure can be done fully automatic

The VBS Script is enclosed here

 ' encap2cisco.vbs, v0.2
' Scripts to convert encap.txt file in Cisco IOS configuration commands
 ' to create Tunnel interfaces and routing to "gateway" traffic for ampr.org.
' For each gateways the script creates a Tunnel interface (starting from # 1001)
' with routing and other detailed cfg commands.
' Before to start keep in mind:
' - Tunnel interfaces are unnumbered of interface declared in MyLoopback variable
' - Public IP address of local gateway is declared in MyPublic variable  
' - Output is to console (use redirecting to save it to a file).
' - Running from command line example: cscript encap2cisco.vbs > cisco.cfg
'
' Tested on Cisco IOS 12.3(22) version
'
' Made by IW0SAB Renzo, free to use and to adapt to specific usages.
' Thanks to IW0RZM Andrea for script suggestions.
' CisarNet Project of Italian Radio Ham Association CISAR
'
' Static entry for Master Tunnel to ampr.org
'!
'interface Tunnel44
'description Tunnel vs. ampr.org (Master tunnel: 44.0.0.0/8)
'! Loopback440 is my main 44.208.0.1 interface
'ip unnumbered Loopback440
'! Loopback1 is my public IP address
'tunnel source Loopback1
'! 160.228.66.251 is main ampr.org tunnel gateway (amprgw.sysnet.ucsd.edu)
'tunnel destination 169.228.66.251
'tunnel mode ipip
'ip route 44.0.0.0 255.0.0.0 Tunnel44
'
' Gubbio (ITALY), 31.10.2011 - Ver 0.2

'

'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("encap.txt", ForReading)
Const ForReading = 1
Dim arrFileLines()
Dim Net, Mask, Gw, Tun, MyNets, MyLoopback, MyPublic, MyCredits
MyNets = Array("44.208/16", "44.134.226/24", "44.134.227/24", "44.134.228/24")
MyPublic = "Loopback1"
MyLoopback = "Loopback440"
MyCredits = "encap2cisco v0.2 by IW0SAB Renzo"
i = 0
Tun = 1000
line = 0
'
' Reading encap.txt file in memory array
'
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'
'Process all encap.txt lines
'
WScript.Echo "!"
WScript.Echo "! Begin of Cisco IOS configuration file generated with " & MyCredits & "("    &  Date & " " & Time & ")"
For Each strLine in arrFileLines

x = Split(strLine, " ") line = line + 1 SkipLine = 0 ' ' Skipping comments... ' If StrComp(x(0),"#") = 0 Then SkipLine = 1 else ' ' ... or it's a subnet of mine ' For Each Network in MyNets If StrComp(Network, x(2)) = 0 Then SkipLine = 1 Next end if ' ' If I need I process this line of encap.txt and create tunnel interfaces for ipip

gateway

' If SkipLine = 0 Then ' ' Extracting variables from current encap.txt line ' Net = MyNet(x(2)) Mask = MyMask(x(2)) Gw = x(4) Tun = Tun + 1 ' ' Generating cisco IOS configuration commands (including remarks) ' WScript.Echo "!" WScript.Echo "! Entry for encap.txt line:(" & line & ")-" & strLine WScript.Echo "!" ' ' remove any previous route to current subnet line of encap.txt ' WScript.Echo "no ip route " & Net & " " & Mask ' ' build cisco cfgs for entry (tunnel interface & route) ' WScript.Echo "interface Tunnel " & Tun WScript.Echo "description Gateway to ampr.org (" & Net & "/" & Mask & ")" WScript.Echo "ip unnumbered " & MyLoopback WScript.Echo "tunnel source " & MyPublic WScript.Echo "tunnel destination " & Gw WScript.Echo "tunnel mode ipip" WScript.Echo "ip route " & Net & " " & Mask & " Tunnel " & Tun & " 200" '

Route Weight is high to be safe evolving to dynamic routing

' End If

Next
WScript.Echo "!"
WScript.Echo "! End of configuration file generated with " & MyCredits
'
' Finished
'
'=====================================================
'
' Function to extract subnet network from line
'
Function MyNet(b)
'	b= "1.2.3.4/24"
'	Wscript.Echo "MyNet b:" & b & " - " & InStr(b,"/")

if InStr(b,"/") <= 0 Then MyNet = b else MyNet = Left(b, InStr(b,"/")- 1) end if Tot = 0 For i = 1 to Len(MyNet) If StrComp(Mid(MyNet,i,1),".") = 0 Then Tot = Tot + 1 End If Next If Tot = 1 Then MyNet = MyNet & ".0.0" End If If Tot = 2 Then MyNet = MyNet & ".0" End If


End Function
'
' Function to extract subnet mask from line
'
Function MyMask(c)
'	c = "1.2.3.4/24"

Num = Right(c, Len(c) - InStr(c, "/")) Select Case Num Case "8" MyMask = "255.0.0.0" Case "9" MyMask = "255.128.0.0" Case "10" MyMask = "255.192.0.0" Case "11" MyMask = "255.224.0.0" Case "12" MyMask = "255.240.0.0" Case "13" MyMask = "255.248.0.0" Case "14" MyMask = "255.252.0.0" Case "15" MyMask = "255.254.0.0" Case "16" MyMask = "255.255.0.0" Case "17" MyMask = "255.255.128.0" Case "18" MyMask = "255.255.192.0" Case "19" MyMask = "255.255.224.0" Case "20" MyMask = "255.255.240.0" Case "21" MyMask = "255.255.248.0" Case "22" MyMask = "255.255.252.0" Case "23" MyMask = "255.255.254.0" Case "24" MyMask = "255.255.255.0" Case "25" MyMask = "255.255.255.128" Case "26" MyMask = "255.255.255.192" Case "27" MyMask = "255.255.255.224" Case "28" MyMask = "255.255.255.240" Case "29" MyMask = "255.255.255.248" Case "30" MyMask = "255.255.255.252" Case "31" MyMask = "255.255.255.254" Case "32" MyMask = "255.255.255.255" Case Else MyMask = "255.255.255.255"

End Select

End Function