Created
May 9, 2016 20:50
-
-
Save andrewjkerr/bdafbf9d307b2479d159a67a1697e745 to your computer and use it in GitHub Desktop.
Prints the MAC addresses of captured packets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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