Skip to content

Instantly share code, notes, and snippets.

@andrewjkerr
Created May 9, 2016 20:50
Show Gist options
  • Save andrewjkerr/bdafbf9d307b2479d159a67a1697e745 to your computer and use it in GitHub Desktop.
Save andrewjkerr/bdafbf9d307b2479d159a67a1697e745 to your computer and use it in GitHub Desktop.
Prints the MAC addresses of captured packets
require 'pcaprub'
snaplength = 65535
promiscous_mode = true
timeout = 0
capture = PCAPRUB::Pcap.open_live('en0', snaplength, promiscous_mode, timeout)
capture.each_packet do |packet|
mac = packet.data.unpack("C*").
map { |i| i.to_s(16) }.
map { |i| if i.length == 1 then "0#{i}" else i end}.
slice(6, 6).
join(":")
puts mac
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment