#!/usr/bin/env python import socket, sys, array # Create an IP raw socket s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) # bind it to an interface address (e.g. tun0 or eth0) s.bind(("10.0.5.1", 0)) # Tell the socket that the IP header is already included s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # ICMP datagram # source = 10.0.5.1 # dest = 74.125.228.6 (google.com) hex_string = '45000054000040004001FD240A0005014A7DE4060800748909900001B1D28E520000000072ED080000000000101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F3031323334353637'; # Convert the hex string to byte array result= array.array('B', hex_string.decode("hex")) # Send it out, not sure why the IP address needs to be repeated here. However, # port number is ignored. n_send = s.sendto(result, ('74.125.228.6',0)); print('sent %d bytes' % n_send); # More example: # http://www.binarytides.com/python-syn-flood-program-raw-sockets-linux/