Skip to content

Instantly share code, notes, and snippets.

@newacct
Forked from rkh/find_mac.rb
Created February 3, 2011 07:02

Revisions

  1. newacct revised this gist Feb 3, 2011. 1 changed file with 17 additions and 17 deletions.
    34 changes: 17 additions & 17 deletions find_mac.rb
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    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
    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
  2. @rkh rkh created this gist Mar 5, 2009.
    18 changes: 18 additions & 0 deletions find_mac.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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