Skip to content

Instantly share code, notes, and snippets.

@bcoles
Created August 5, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcoles/999b54addf615782c65a1b0f68f922e1 to your computer and use it in GitHub Desktop.
Save bcoles/999b54addf615782c65a1b0f68f922e1 to your computer and use it in GitHub Desktop.
Cain Wireless Scanner export to CSV
#!/usr/bin/env ruby
################################################################################
# Cain Wireless Scanner export to CSV #
# ----------------------------------- #
# This script takes a text file of wireless networks exported from Cain #
# and converts it to CSV. #
################################################################################
# ~ bcoles
require 'csv'
VERBOSE = false
file = ARGV.first
if file.nil? || !File.exist?(file)
$stderr.puts "[-] Error: file '#{file}' does not exist"
exit 1
end
$stderr.puts "[*] Reading '#{file}'..."
f = File.open(ARGV[0])
file_data = f.read
f.close
wifi_networks = file_data.scan(/^(BSSID: .*?Unique WEP IVs: \d+)\r?\n/m)
if wifi_networks.empty?
$stderr.puts "[-] Error: found no wireless networks"
exit 1
end
$stderr.puts "[+] Found #{wifi_networks.size} wireless networks"
headings = ['BSSID', 'Last seen', 'Vendor', 'Signal', 'SSID', 'Enc', 'Mode', 'Channel', 'Rates (Mbps)', 'Packets', 'Unique WEP IVs']
csv_string = CSV.generate(force_quotes: true) do |csv|
csv << headings
wifi_networks.each do |w|
network = []
headings.each do |h|
network << w.flatten.first.scan(/^#{h}: (.*)?\r?\n/).flatten.first
end
$stderr.puts network.inspect if VERBOSE
$stderr.puts '-' * 80 if VERBOSE
csv << network
end
end
$stdout.puts csv_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment