#!/usr/bin/python
import libnet
import string
import libnetc
tgt_eth='\x00\x00\x00\x00\x00\x00'
broadcast_eth='\xff\xff\xff\xff\xff\xff'
src_ip='\xc0\xa8\x01\x02'
tgt_ip='\xc0\xa8\x01\x01'
#payload='arp packets can carry data? who knew!'
payload=None
def dumphex(s):
bytes = map(lambda x: '%.2x ' % x, map(ord, s))
if len(s)>16:
for i in range((len(s)+16)/16*16, 15, -16):
bytes.insert(i,'\n')
print string.join(bytes, '')
if __name__=="__main__":
ifc = libnet.interface()
ifc.open_link(libnet.select_device(None))
src_eth = ifc.get_hwaddr()
print 'source ethernet address:'
dumphex (src_eth)
pkt = libnet.packet()
pkt.build_arp(libnetc.ARPHRD_ETHER,
libnetc.ETHERTYPE_IP,
libnetc.ETHER_ADDR_LEN,
4,
libnetc.ARPOP_REQUEST,
src_eth,
src_ip,
tgt_eth,
tgt_ip)
pkt.build_ethernet(broadcast_eth,src_eth, libnetc.ETHERTYPE_ARP)
dumphex(pkt.getvalue())
ifc.write(pkt)
syntax highlighted by Code2HTML, v. 0.9.1