libpcap bindings for ruby
C Ruby
Latest commit 340c88d Apr 18, 2016 @shadowbq shadowbq added tests for open_dead



Join the chat at

Build Status Windows Builds Gem Version Dependency Status

This goal of this project is to provide a consistent interface to LBL's libpcap packet capture library.


This does not provide packet processing functionality, it simply provides the interface for capturing packets, and passing yielding those packets.

For packet processing capability look at ruby gems PCAPFU, PCAPLET, etc..


MRI POSIX Ruby (Native compilation) [Travis-CI Tested]

Ruby 1.8.7  (EOL June 2014)
Ruby 1.9.3
~> Ruby 2.x 

libpcap -

Ruby with DevKit(32bit) on Windows [AppVeyor Tested]

Ruby 1.9.3
~> Ruby 2.x

WinPcap Developer's Pack -


gem install pcaprub

Advanced options in a Windows ENV

gem install pcaprub --no-ri --no-rdoc -- --with-pcap-dir="c:/dev/src/WpdPack"


require 'rubygems'
require 'pcaprub'

cap =

Current Repository for Gemcutter source

The Git Repo on Github @pcaprub is forked from the Metasploit SVN repo

git clone git://


Notes on 0.11.x series and beyond.

The gem is now a module. The module is autoincluded, but this helps with name collisions and additional growth.

Some of the Error handling and basic intensive code is moving out the C base-extension (ext) and into native Ruby.

The file handling in dumper is now attached to the Capture Class and not the Module as an additional singleton.

capture = PCAPRUB::Pcap.open_live('eth0', SNAPLENGTH, true, 0)
  { ... }

Timstamps from the PCAP Header

Timestamps are now available when yeilding packets instead of strings

capture = PCAPRUB::Pcap.open_live('eth0', SNAPLENGTH, true, 0)
capture.each_packet do |packet|
  puts "micro => #{packet.microsec}"

Ruby 1.8.7 & WinPcap

On Ruby 1.8 with winpcap, rb_thread_polling pauses for 100 milliseconds between reads. This may mean some packets are missed.


GNU Lesser General Public License v2.1 (LGPL-2.1)

See LICENCE for details

Copyright © 2010 - 2014

Notes on other repositories in compliance with LGPL-2.1

All original code maintains its copyright from its original authors and licensing.

On March 2014 this project was migrated to from

The Git Repo on Github @pcaprub is a forked merge from the Metasploit SVN repo

git clone git:// (moved)

The Metasploit Project also provides a Subversion repository: (0.9-dev)

svn checkout

Packetfu Project also provides a listing (0.9-dev)

The Marshall Beddoe's Outdate RubyForge svn version can be obtained from Subversion: (0.7-dev)

svn checkout
http download Public Rubyforge (0.6)

SourceForge Masaki Fukushima 2000 (0.6) – Object Creation Heavy Implementation (PCAPLET integrated)

Additonal Github Repos (0.8-dev) /pcaprub-spox  (0.8-dev+)