Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Created May 31, 2012 16:30
Show Gist options
  • Save pachacamac/2844590 to your computer and use it in GitHub Desktop.
Save pachacamac/2844590 to your computer and use it in GitHub Desktop.
station_scanner.rb
require 'time'
KNOWN_MACS = {
'**:**:**:**:**:**' => 'Marcs Handy'
}
def oui_lookup(mac)
owner = KNOWN_MACS[mac] || 'unknown'
oui = mac.upcase.tr(': ','-')[0..7]
vendor = `grep '^#{oui}' oui.txt | cut -f3`.strip
"#{owner} - #{vendor}"
rescue
$!
end
macs = {}
f = IO.popen "tshark -i mon0 -l -R 'wlan.fc.type_subtype == 0x04' -Tfields -e frame.time -e wlan.sa -e wlan.da -e radiotap.dbm_antsignal -e radiotap.dbm_antnoise"
last_mac = nil
while true
data = f.readline.strip.split("\t")
time = Time.parse data[0]
mac = data[1]
signal = data[3]
last_time = macs[mac]
macs[mac] = time
time_diff = time - last_time if last_time
puts "#{mac}\t#{(time_diff||-1).round}\t#{oui_lookup(mac)}\t#{signal}\t(#{macs.size})" if !last_time || (time_diff && time_diff > 2)
last_mac = mac
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment