Skip to content

Instantly share code, notes, and snippets.

@gb-swatanabe
Last active December 21, 2015 18:59
Show Gist options
  • Save gb-swatanabe/6350773 to your computer and use it in GitHub Desktop.
Save gb-swatanabe/6350773 to your computer and use it in GitHub Desktop.
MACアドレスを引数に指定するとOUIベンダコードを検索するスクリプト (クエリ先: http://standards.ieee.org/develop/regauth/oui/public.html )
#!/usr/bin/env ruby
require "net/http"
query_url = 'http://standards.ieee.org/cgi-bin/ouisearch'
irregular = {
"080027" => "VirtualBox Guest",
"525400" => "QEMU/KVM Guest",
}
def help
printf "usage: %s MAC_ADDRESS\n", $0
exit
end
if ARGV.length != 1 then
help
end
mac = ARGV[0].gsub(/[\.\:\-]/,'').downcase
if /^([\da-f]{6})/ =~ mac then
code = $1
uri = URI.parse(query_url)
resp, body = Net::HTTP.post_form(uri, :x => code)
if /no match for the query/ =~ body then
printf "The public OUI listing contains no match for the query %s\n", code
else
puts body.gsub(/\A.*\<pre\>|\<\/pre\>.*\Z|\<[a-z\/\s]+\>/m,'')
end
if irregular.has_key?(code) then
printf "\n\t\t(may be: %s)\n", irregular[code]
end
else
help
end
$ ./ouisearch 08:00:27:1a:2b:3c
08-00-27 (hex) CADMUS COMPUTER SYSTEMS
080027 (base 16) CADMUS COMPUTER SYSTEMS
600 SUFFOLK ST
LOWELL MA 08154
UNITED STATES
(may be: VirtualBox Guest)
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment