Skip to content

Instantly share code, notes, and snippets.

@Hexa
Created July 29, 2014 13:49
Show Gist options
  • Select an option

  • Save Hexa/cbbf53042e0aa9418759 to your computer and use it in GitHub Desktop.

Select an option

Save Hexa/cbbf53042e0aa9418759 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'ethernet'
ETHER_NAME = 'lxcbr0'
socket = Ethernet.socket(ETHER_NAME, 0x0806)
OPERATION = 0x0002
dest_hw_address = Ethernet::Devices.mac(ETHER_NAME)
loop do
message = socket.recv_from(4096)[0]
hardware_type, protocol_type, hardware_len, protocol_len, operation, src_hw_address, src_protocol_address, _dest_hw_address, dest_protocol_address, _ = message.unpack('a2a2a1a1a2a6a4a6a4a*')
if protocol_type == [0x0800].pack('n')
if operation == [0x0001].pack('n')
data = [hardware_type, protocol_type, hardware_len, protocol_len, OPERATION, dest_hw_address, dest_protocol_address, src_hw_address, src_protocol_address].pack('a2a2a1a1na6a4a6a4')
socket.send_to(src_hw_address, data + 0x00.chr * 14)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment