pylibnet is a python module for the libnet packet injection library that was originally developed by David Margrave at the time of libnet 0.9.8a. The project has since been revived and is now under active maintenance by Nadeem Douba. The project now features support for libnet 1.1.x and has all of the packet building functionality that is provided by libnet. You can download the latest from here.
Some of the packet chaining and context queuing functionality that is available in libnet is still not available in the current release of pylibnet. However, it will be coming very soon.
You can download the latest from here
The script below shows how easy it is to make an ARP request packet with pylibnet.
Code for ARP request:
#!/usr/bin/python
l = libnet.context(libnet.RAW4, 'eth0')
src_ip = l.get_ipaddr4()
src_eth = l.get_hwaddr()
dst_ip = l.name2addr4('192.168.0.1', libnet.DONT_RESOLVE)
dst_eth = '\xff'*6
arp_tag = l.autobuild_arp(libnet.ARPOP_REQUEST, src_ip, src_eth, dst_ip, dst_eth)
eth_tag = l.autobuild_ethernet(dst_eth, libnet.ETHERTYPE_ARP)
print 'ARP request:'
print l.getpbuf(arp_tag)
print 'Ethernet Frame:'
print l.getpbuf(eth_tag)
l.write()