Created
June 11, 2019 02:26
-
-
Save metalefty/05cc9c72be097683a07c5e50eabb09cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
mac_vendors = Hash.new | |
File.open('./oui.txt') do |f| | |
array = f.readlines | |
array.each do |e| | |
next unless e =~ /\(hex\)/ | |
k, v = e.split(/\(hex\)/) | |
mac_vendors.store(k&.gsub(/-/, ':')&.strip&.upcase, v&.strip) | |
end | |
end | |
mac_addrs = Array.new | |
$stdin.each_line do |l| | |
next unless l =~ /DHCPACK/ | |
mac_addr = l.match(/([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/).to_s | |
mac_addrs << mac_addr.upcase | |
end | |
uniq_mac_addrs = mac_addrs.uniq | |
appeared_mac_vendors = Array.new | |
uniq_mac_addrs.each do |mac| | |
appeared_mac_vendors << (mac_vendors[mac[0..7]] || "unknown (#{mac[0..7]})") | |
end | |
count = Hash.new(0) | |
appeared_mac_vendors.each do |e| | |
count[e] += 1 | |
end | |
count.sort.reverse.sort_by{|k,v| v}.reverse.each do |k,v| | |
printf "%4d\t%s\n", v, k | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment