#!/usr/bin/python import libnetc import string src_ip=libnetc.name_resolve('192.168.1.2',0) tgt_ip=libnetc.name_resolve('192.168.1.1',0) 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 = libnetc.new_interface() libnetc.interface_open_raw(ifc, libnetc.IPPROTO_RAW) pkt = libnetc.build_tcp(1025, 80, 1, 0, libnetc.TH_SYN, 0, 0) dumphex(pkt) pkt = libnetc.build_ip(len(pkt), 0, 1, 0, 255, libnetc.IPPROTO_TCP, src_ip, tgt_ip) + pkt dumphex(pkt) libnetc.do_checksum(pkt, libnetc.IPPROTO_TCP, libnetc.TCP_H) print 'tcp syn:' dumphex(pkt) libnetc.interface_write(ifc, pkt)