Guest User

Untitled

a guest
Mar 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import paramiko
  2. import time
  3. from ciscoconfparse import CiscoConfParse
  4. import getpass
  5. import os
  6.  
  7. ip = input("type missing host portion: 10.11.2.")
  8. HOST = ("10.11.2." + ip)
  9. username = "vandric"
  10. password = getpass.getpass('Password: ')
  11. portViolation = "no detected port security violations on this switch"
  12. txtFile = HOST + " Port Security Violation"
  13.  
  14.  
  15. ssh = paramiko.SSHClient()
  16. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17. ssh.connect(hostname=HOST, username=username, password=password)
  18.  
  19. print('successful connection to ip address ', HOST+ '\n')
  20.  
  21. remote_connection = ssh.invoke_shell()
  22.  
  23. remote_connection.send("enable\n")
  24. remote_connection.send("T3ugljev1k\n")
  25. remote_connection.send("Terminal length 0\n")
  26. remote_connection.send("show port\n")
  27.  
  28.  
  29. time.sleep(1)
  30. output = remote_connection.recv(65535)
  31.  
  32. ports = output.decode()
  33.  
  34. path = txtFile
  35. openfile = open(path, 'w')
  36.  
  37. openfile.write(ports)
  38. openfile.close()
  39.  
  40.  
  41. #ciscoconfParse from txt file, picks line which containts security violatio above 0 (zero)
  42.  
  43. parse = CiscoConfParse(path)
  44. findPorts = parse.find_lines(r'[1-9]\s+(Restrict|Shutdown)')
  45. for port in findPorts:
  46. print(" Secure Port MaxSecureAddr CurrentAddr SecurityViolation Security Action")
  47. print(' (Count) (Count) (Count)')
  48. print(port)
  49. print(port[2:13])
Add Comment
Please, Sign In to add comment