Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import nmap, time
- start_time = time.time()
- def scan_subnet_for_ssh_cisco(subnet):
- ### Function scanning subnet with nmap (ports tcp/22, tcp/23) and finding cisco ios devices
- ### returning dictionary with ip address and connection method (telnet, ssh)
- ip_dict = {}
- nm = nmap.PortScanner()
- nm.scan(subnet, '22-23')
- for host in nm.all_hosts():
- if nm[host]['tcp'][22]['cpe'] == "cpe:/o:cisco:ios": # check if device is cisco:ios and has ssh enabled
- ip_dict[host] = "ssh"
- else:
- if nm[host]['tcp'][23]['cpe'] == "cpe:/o:cisco:ios": #check if device is cisco:ios and has telnet enabled
- ip_dict[host] = "telnet"
- return ip_dict
- z = {}
- subnet = '192.168.10.0/24' ### subnet - change it for your requirements
- dict = scan_subnet_for_ssh_cisco(subnet)
- print dict
- print("--- Total runtime %s seconds ---" % round((time.time() - start_time),2))
Add Comment
Please, Sign In to add comment