Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import time
- from ciscoconfparse import CiscoConfParse
- import getpass
- import os
- ip = input("type missing host portion: 10.11.2.")
- HOST = ("10.11.2." + ip)
- username = "vandric"
- password = getpass.getpass('Password: ')
- portViolation = "no detected port security violations on this switch"
- txtFile = HOST + " Port Security Violation"
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=HOST, username=username, password=password)
- print('successful connection to ip address ', HOST+ '\n')
- remote_connection = ssh.invoke_shell()
- remote_connection.send("enable\n")
- remote_connection.send("T3ugljev1k\n")
- remote_connection.send("Terminal length 0\n")
- remote_connection.send("show port\n")
- time.sleep(1)
- output = remote_connection.recv(65535)
- ports = output.decode()
- path = txtFile
- openfile = open(path, 'w')
- openfile.write(ports)
- openfile.close()
- #ciscoconfParse from txt file, picks line which containts security violatio above 0 (zero)
- parse = CiscoConfParse(path)
- findPorts = parse.find_lines(r'[1-9]\s+(Restrict|Shutdown)')
- for port in findPorts:
- print(" Secure Port MaxSecureAddr CurrentAddr SecurityViolation Security Action")
- print(' (Count) (Count) (Count)')
- print(port)
- print(port[2:13])
Add Comment
Please, Sign In to add comment