Easiest way to "fill" payload?
<p>I wan't to send a UDP packet with a arbitrary packet size depending on my input argument, so whenever my "data" is not enough to fill up the wanted packet payload I want to just "fill" the rest with empty data.</p>

<p>So if I send <code>123</code> but I want the packet to be of size 100 bytes, the method will pad the packet with the access data, I don't want to iterate and add spaces to fill it out manually. </p>

<p>Any tips?</p>

<p>Try this way:</p>

<pre><code>&gt;&gt;&gt; from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)
&gt;&gt;&gt; p = IP(dst="62.21.20.21")/UDP()
&gt;&gt;&gt; p = p/Raw('a'*(100-len(p)))
&gt;&gt;&gt; send(p)
.
Sent 1 packets.
&gt;&gt;&gt;

# tcpdump -ni cplane0 udp -e -v -X
tcpdump: listening on cplane0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:15:31.904204 54:ab:3a:56:59:1e &gt; fa:16:3e:e1:9e:14, ethertype IPv4 (0x0800), length 114: (tos 0x0, ttl 62, id 1, offset 0, flags [none], proto UDP (17), length 100)
    44.60.11.3.53 &gt; 62.21.20.21.53: 24929 updateM+ [b2&amp;3=0x6161] [24929a] [24929q] [24929n] [24929au][|domain]
        0x0000:  4500 0064 0001 0000 3e11 f31f 2c3c 0b03  E..d....&gt;...,&lt;..
        0x0010:  3e15 1415 0035 0035 0050 c3c9 6161 6161  &gt;....5.5.P..aaaa
        0x0020:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0030:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0040:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0050:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0060:  6161 6161                                aaaa
</code></pre>

<p>Please note "proto UDP (17), length 100" in tcpdump output.</p>

python sockets udp scapy