Guest User

Untitled

a guest
Jan 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import nmap, time
  4.  
  5. start_time = time.time()
  6.  
  7. def scan_subnet_for_ssh_cisco(subnet):
  8. ### Function scanning subnet with nmap (ports tcp/22, tcp/23) and finding cisco ios devices
  9. ### returning dictionary with ip address and connection method (telnet, ssh)
  10.  
  11. ip_dict = {}
  12. nm = nmap.PortScanner()
  13. nm.scan(subnet, '22-23')
  14. for host in nm.all_hosts():
  15. if nm[host]['tcp'][22]['cpe'] == "cpe:/o:cisco:ios": # check if device is cisco:ios and has ssh enabled
  16. ip_dict[host] = "ssh"
  17. else:
  18. if nm[host]['tcp'][23]['cpe'] == "cpe:/o:cisco:ios": #check if device is cisco:ios and has telnet enabled
  19. ip_dict[host] = "telnet"
  20. return ip_dict
  21.  
  22. z = {}
  23. subnet = '192.168.10.0/24' ### subnet - change it for your requirements
  24.  
  25. dict = scan_subnet_for_ssh_cisco(subnet)
  26.  
  27. print dict
  28.  
  29. print("--- Total runtime %s seconds ---" % round((time.time() - start_time),2))
Add Comment
Please, Sign In to add comment