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>I'm not a networking expert, but you might want to take a look at <a href="https://docs.python.org/3.5/library/struct.html" rel="nofollow">struct.pack()</a></p>

<p>This will zero pad a length of characters and should be blazing fast:</p>

<pre><code>from struct import pack

result = pack('!100s', 'input_value')
</code></pre>

<p>This also allows you to mind the endian-ness of your data if that is important in your domain. In this case the data appears right null padded.</p>

<p>Hope that helps!</p>

python sockets udp scapy