lemontree55 / packetgen

Ruby library to easily generate and capture network packets
MIT License
98 stars 13 forks source link

default capture device doesn't exist on macOS #76

Closed picatz closed 6 years ago

picatz commented 6 years ago

๐Ÿ‘‹ Hello @sdaubert, I really hope you're doing well!

This morning I decided to run rspec on this repository and came across an error on macOS:

../packetgen/lib/packetgen/capture.rb:65:in `open_live': lo: No such device exists (BIOCSETIF failed: Device not configured) (RuntimeError)

I believe this to be attributed to the default capture interface lo. On macOS, perhaps at the very least on my laptop, the loopback interface is named lo0.

Interfacez

I wrote a gem a little while back called interfacez. This gem uses the Ruby standard library under the hood and provides a clean semantics for this behavior I think we're looking for. Moreover, I really think it could be a replacement for NetworkInterface ( written by Rapid7, with lots of slow C bindings ) and event Pcap.lookupdev.

Example Usage

require 'interfacez'

# check if loopback exists
Interfacez.loopback?
# => true

# get loopback
Interfacez.loopback
# => "lo0"

# get first network interface to capture on ( lookupdev )
Interfacez.default
# => "en0"
sdaubert commented 6 years ago

hey! that's a great gem :tada:

I will have a look at it, when i will have some time :confused:

picatz commented 6 years ago

Thanks! ๐Ÿ™‡

If you are interested, I can spend some time this week replacing network_interface with interfacez.

sdaubert commented 6 years ago

Yes, this could help.

sdaubert commented 6 years ago

@picatz may you add a method to get hwaddr (ie MAC address) on a given interface? This should help to replace NetworkInterface by Interfacez.

picatz commented 6 years ago

@sdaubert I think I should be able to implement that. ๐Ÿ‘

picatz commented 6 years ago

@sdaubert Got those issues addressed. I released new gem version (1.0.3) ๐ŸŽ‰

sdaubert commented 6 years ago

Should be fixed by #85

picatz commented 6 years ago

@sdaubert That's awesome! ๐ŸŽ‰ โค๏ธ โœจ