title: How to spoof the IP address in a UDP packet with scapy
body: <p>I'm testing the security infrastructure on my server, running an application that accepts UDP traffic on port 7777. In order to do that, I want to send UDP packets to query for information about the application, but using a spoofed IP source.</p>
  <p>Here is the packet I'm trying to send:</p>
  <p><img src="https://i.stack.imgur.com/kmUPx.png" alt="" /></p>
  <p>I've tried doing this with scapy, but it looks like the packet is not received on the other side, where I have tcpdump listening for UDP packets on port 7777.</p>
  <p>This is the code I've tried:</p>
  <pre><code>from scapy.all import *
  import random
  
  D = 7777 # destination port
  opcode = 'd'
  target_ip = &quot;1.1.1.1&quot;
  ips = target_ip.split('.'); # Target IP
  
  payload = &quot;SAMP{0}{1}{2}{3}{4}{5}{6}&quot;.format(chr(int(ips[0])), chr(int(ips[1])), chr(int(ips[2])), chr(int(ips[3])), chr(D &amp; 0xFF), chr(D » 8 &amp; 0xFF), opcode)
  
  ip1 = 84
  ip2 = random.randint(1,255)
  ip3 = random.randint(1,255)
  ip4 = random.randint(1,255)
  
  A = str(ip1) + &quot;.&quot; + str(ip2) + &quot;.&quot; + str(ip3) + &quot;.&quot; + str(ip4)
  
  send(IP(src=A, dst=target_ip)/UDP(dport=D)/Raw(load=payload))
  </code></pre>
  <p>When I run, it says &quot;Sent 1 packet&quot;, however I cannot see the packets in the other side when using tcpdump like this:</p>
  <pre><code>tcpdump -t -n -v -B 99999 -i gre1 -XX udp dst port 7777
  </code></pre>
  <p>I've tried with two different target IPs, both have port 7777 opened.</p>
  <blockquote>
  <p>The payload I want to send is basically 53 41 4D 50 C0 A8 C8 67 61 1E
  69, from a spoofed IP src.</p>
  </blockquote>