Skip to content

Instantly share code, notes, and snippets.

@newacct
Forked from rkh/find_mac.rb
Created February 3, 2011 07:02
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 newacct/809146 to your computer and use it in GitHub Desktop.
Save newacct/809146 to your computer and use it in GitHub Desktop.
require "rubygems"
require "snmp"
mac = ARGV.shift.dup
unless mac.gsub! /^(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?(..)[-: ]?$/, '\1 \2 \3 \4 \5 \6'
puts "illegal mac"
exit
end
mac = mac.split(" ").collect { |x| x.hex }.join "."
%w[240 113 175 184 185 179 241 193 194 176 177 178 202].each do |ip|
SNMP::Manager.open(:Host => "192.168.1.#{ip}") do |snmp|
value = snmp.get_value("SNMPv2-SMI::mib-2.17.4.3.1.2.#{mac}")
puts "192.168.1.#{ip}, port #{value}" unless value.to_s =~ /noSuchInstance/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment