Advertisement
Guest User

Send ICMP through Raw Socket

a guest
Nov 21st, 2013
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import socket, sys, array
  3.  
  4. # Create an IP raw socket
  5. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
  6.  
  7. # bind it to an interface address (e.g. tun0 or eth0)
  8. s.bind(("10.0.5.1", 0))
  9.  
  10. # Tell the socket that the IP header is already included
  11. s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
  12.  
  13. # ICMP datagram
  14. # source = 10.0.5.1
  15. # dest = 74.125.228.6 (google.com)
  16. hex_string = '45000054000040004001FD240A0005014A7DE4060800748909900001B1D28E520000000072ED080000000000101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F3031323334353637';
  17.  
  18. # Convert the hex string to byte array
  19. result= array.array('B', hex_string.decode("hex"))
  20.  
  21. # Send it out, not sure why the IP address needs to be repeated here. However,
  22. # port number is ignored.
  23. n_send = s.sendto(result, ('74.125.228.6',0));
  24.  
  25. print('sent %d bytes' % n_send);
  26.  
  27. # More example:
  28. # http://www.binarytides.com/python-syn-flood-program-raw-sockets-linux/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement