Friday, 25 January 2019

OSPF route selection Criteria

Below are the path selection criteria for OSPF:-

1. Prefix Length
2. Administrative Distance
3. Metric
4. Route Type- Order of route priority is explained below:-
  • Intra-Area (O)
  • Inter-Area (O IA)
  • External Type 1 (E1)
  • External Type 2 (E2)
  • NSSA Type 1 (N1)
  • NSSA Type 2 (N2)
5. Load Balance

Monday, 12 February 2018

IP SLA and its traps



Below is the SLA configuration and snmp configuration required to generate the Traps for SLA activity.


ip sla 5


icmp-echo 192.168.100.1


ip sla schedule 5 life forever start-time now


 


ip sla reaction-configuration 5 react timeout threshold-type immediate action-type trapOnly


ip sla logging traps


ip sla enable reaction-alerts


 


snmp-server enable traps syslog


snmp-server enable traps ipsla


snmp-server host 192.168.1.2 version 2c Monitoring_server_string  syslog



Wednesday, 27 September 2017

Python for network engineer:- Configure multiple router using SSH :- Python2.7

import paramiko
import time
import sys
import logging
import socket

remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# store router ip in ip.txt file in same folder where script is.
ips = [i.strip() for i in open("ip.txt")]

g = open('config.txt', 'r+')# store configuration in config.txt file in same folder where script is.
str = g.read()
g.close

for ip in ips:
    try:
        remote_conn_pre.connect(ip, username='test', password='test', timeout=4, look_for_keys=False, allow_agent=False)

        remote_conn = remote_conn_pre.invoke_shell()
        print (ip + ' === Device Reachable')
        remote_conn.send("\n")
        remote_conn.send((str))
        time.sleep(2)
        #output = remote_conn.recv(5000)
        #print (output)
    except paramiko.AuthenticationException:
        print ip + ' === Bad credentials'
    except paramiko.SSHException:
        print ip + ' === Issues with ssh service'
    except socket.error:
        print ip + ' === Device unreachable'

Saturday, 23 September 2017

Python for network engineer: cisco device backup using SSH : python2.7

Below script will take the backup of cisco devices in the folder where you have stored your python script. Please make sure ip.txt file(which contains router IP address) is also in same folder.

Below is the sample ip.txt file.


import paramiko
import time
import datetime

ssh1 = paramiko.SSHClient()
ssh1.set_missing_host_key_policy(paramiko.AutoAddPolicy())

now = datetime.datetime.now()

#open file in read mode
#ip.txt is a text file which contains routers IP address. Make sure it is stored in same folder #where the python script is. 
f = open("ip.txt","r")
lines = f.readlines()
f.close()

#open file in write mode and remove spaces between rows.

f = open("ip.txt","w")
for line in lines:
    if line!=""+"\n":
        f.write(line)
f.close()

ips = [i.strip() for i in open("ip.txt")]

for ip in ips:
    try:
        filename_prefix = (ip)
        ssh1.connect(ip,username='test', password='test')
        ssh = ssh1.invoke_shell()
        time.sleep(5)
        print ip
        ssh.send("\nterminal length 0\n")
        ssh.send("show run\n")
        time.sleep(5)
        output = ssh.recv(65535)
        print output
        filename = "%s_%.2i-%.2i-%i_%.2i-%.2i-%.2i" % (filename_prefix,now.day,now.month,now.year,now.hour,now.minute,now.second)
        fp=open(filename,"w")
        fp.write(output)
        fp.close()
       
    except:
        response = 'Failed'
        print (ip + " is not reachable")




Friday, 22 September 2017

Python for network Engineer:- SSH to cisco router and run multiple commands :- python2.7

import paramiko
import time
#from getpass import getpass

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.10.1', username='test', password='test')


ssh = ssh.invoke_shell()

ssh.send("show ip int brief\n")
time.sleep(1)
output = ssh.recv(65535)
print output
time.sleep(5)
ssh.send("sh ver\n")
time.sleep(1)
output = ssh.recv(65535)
print output


Monday, 18 September 2017

How to remove rows with specific text from the notepad using python 2.7

Below script is used to remove specific text from notepad.

Below script is used to remove specific text from the notepad using python. To demonstrate the same we have used a file which has “networking” word in the file.

#open the file in read mode which you need to modify, we have used ip.txt file.
file= open("ip.txt","r")
# Read the file
lines = file.readlines()
# close the file
file.close()

# Read the file in write mode
file = open("ip.txt","w")
# Reading each line and writing text, which is not a "networking" word, back to the file.
for line in lines:
    if line!="networking"+"\n":
        file.write(line)
file.close()

Before the script execution, ip.txt contains below content. You can see that below file contains word "networking" in many rows and our onjective is to remove all the rows which contains word "networking".






















After script execution, all rows containing  word "networking" has been deleted.

  

How to remove empty rows from notepad using Python 2.7

Below script is used to remove empty rows from notepad.

#open the file in read mode which you need to modify, we  have used ip.txt file.
file= open("ip.txt","r")
# Read the file
lines = file.readlines()
# close the file
file.close()

# Read the file in write mode
file = open("ip.txt","w")
# Reading each line and writing text which is not a space back to the file.
for line in lines:
    if line!=""+"\n":
        file.write(line)
file.close()

Before the script execution, ip.txt contains below content. You can see there are various spaces in it.




















After script execution, All empty rows has been deleting from the file.