MCPcopy Index your code
hub / github.com/secdev/scapy / replace

Method replace

scapy/plist.py:658–690  ·  view source on GitHub ↗

lst.replace( ,[ ,] ) lst.replace( (fld,[ov],nv),(fld,[ov,]nv),...) if ov is None, all values are replaced ex: lst.replace( IP.src, "192.168.1.1", "10.0.0.1" ) lst.replace( IP.ttl, 64 ) lst.replace( (IP.ttl, 64),

(self, *args, **kargs)

Source from the content-addressed store, hash-verified

656 return dict(sessions)
657
658 def replace(self, *args, **kargs):
659 # type: (Any, Any) -> PacketList
660 """
661 lst.replace(<field>,[<oldvalue>,]<newvalue>)
662 lst.replace( (fld,[ov],nv),(fld,[ov,]nv),...)
663 if ov is None, all values are replaced
664 ex:
665 lst.replace( IP.src, "192.168.1.1", "10.0.0.1" )
666 lst.replace( IP.ttl, 64 )
667 lst.replace( (IP.ttl, 64), (TCP.sport, 666, 777), )
668 """
669 delete_checksums = kargs.get("delete_checksums", False)
670 x = PacketList(name="Replaced %s" % self.listname)
671 if not isinstance(args[0], tuple):
672 args = (args,)
673 for _p in self.res:
674 p = self._elt2pkt(_p)
675 copied = False
676 for scheme in args:
677 fld = scheme[0]
678 old = scheme[1] # not used if len(scheme) == 2
679 new = scheme[-1]
680 for o in fld.owners:
681 if o in p:
682 if len(scheme) == 2 or p[o].getfieldval(fld.name) == old: # noqa: E501
683 if not copied:
684 p = p.copy()
685 if delete_checksums:
686 p.delete_checksums()
687 copied = True
688 setattr(p[o], fld.name, new)
689 x.append(p)
690 return x
691
692 def getlayer(self, cls, # type: Packet
693 nb=None, # type: Optional[int]

Callers 15

routeMethod · 0.80
__init__Method · 0.80
_fixMethod · 0.80
long_converterFunction · 0.80
import_hexcapFunction · 0.80
AutoArgparseFunction · 0.80
__getattr__Method · 0.80
_show_or_dumpMethod · 0.80
exploreFunction · 0.80
_iterfieldsFunction · 0.80
to_htmlFunction · 0.80
to_latexFunction · 0.80

Calls 6

_elt2pktMethod · 0.95
PacketListClass · 0.85
getMethod · 0.45
getfieldvalMethod · 0.45
copyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected