Skip to content

Instantly share code, notes, and snippets.

@rkh
Created March 5, 2009 17:05
Show Gist options
  • Save rkh/74436 to your computer and use it in GitHub Desktop.
Save rkh/74436 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 { |hex| eval("0x#{hex}").to_s }.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