Skip to content

Instantly share code, notes, and snippets.

@physacco
Last active December 15, 2015 23:59
Show Gist options
  • Select an option

  • Save physacco/5344398 to your computer and use it in GitHub Desktop.

Select an option

Save physacco/5344398 to your computer and use it in GitHub Desktop.
Usage of the ruby-pcap gem.

Pcaplet example

# examples/tcpdump.rb
require 'pcaplet'
include Pcap

pcaplet = Pcaplet.new
pcaplet.each_packet do |pkt|

  # available methods of pkt:
  # Packet type:
  pkt.ip?
  pkt.tcp?
  pkt.udp?

  # IP address:
  pkt.ip_src
  pkt.src
  pkt.ip_dst
  pkt.dst

  # TCP/UDP port:
  pkt.sport
  pkt.udp_sport
  pkt.dport
  pkt.udp_dport

  # Timestamp:
  pkt.time
  pkt.time_i

  # Size:
  pkt.size
  pkt.caplen
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment