Kingslayer
Kingslayer

Reputation: 53

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.

Upvotes: 0

Views: 1975

Answers (2)

Cukic0d
Cukic0d

Reputation: 5421

Have a look at the sprintf documentation using either help(Packet.sprintf) or using the online documentation: https://scapy.readthedocs.io/en/latest/api/scapy.packet.html#scapy.packet.Packet.sprintf

sprintf is a function to format a packet's data in a human readable form.

Upvotes: 0

qouify
qouify

Reputation: 3920

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

Upvotes: 2

Related Questions