Search code examples
pythonscapyethernetarp

Python scapy sprintf syntax


ans,uans=srp(Ether(...)/ARP(pdst="x.x.x.x"),...)
for snd,rcv in ans:
  return rcv.sprintf(r"%Ether.src%") 

Let's say I find the mac address of an IP using the above method. What does r in sprintf() mean and what is returned here? This may be a silly question but I'm not able to find an answer and I'm new to python. That's why I posted it here.


Solution

  • The r prefix has nothing to do with scapy. r means raw string. This means that backslashes in the string are treated as literal characters. See python docs.

    For instance:

    >>> print(r'\n')
    \n