Skip to content

Instantly share code, notes, and snippets.

@hackworth
Created August 15, 2013 01:58
Show Gist options
  • Save hackworth/6237589 to your computer and use it in GitHub Desktop.
Save hackworth/6237589 to your computer and use it in GitHub Desktop.
Watir script for getting hostnames from Cisco 1130 AG access points
require 'watir-webdriver'
puts "Running Scan"
scan = %x(sudo nmap -PR -sn 10.208.0.0/22 | grep Cisco -B 2 | grep Nmap | sed 's/Nmap scan report for //')
puts "Running Webdriver"
noname = Array[]
browser = Watir::Browser.new
scan.lines.each do |host|
browser.goto "http://Cisco:Cisco@#{host}"
hostname = browser.text.lines.grep(/Hostname/)[0]
host = host.split(/\n/)[0]
if hostname
hostname = hostname.gsub(/Hostname\s+/, '')
puts "#{host} #{hostname}"
else
noname.push(host)
end
end
puts "Unknown Hostnames:"
noname.each { |h| puts h }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment