当前位置: 首页>>代码示例>>Python>>正文


Python utils.checksum方法代码示例

本文整理汇总了Python中scapy.utils.checksum方法的典型用法代码示例。如果您正苦于以下问题:Python utils.checksum方法的具体用法?Python utils.checksum怎么用?Python utils.checksum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scapy.utils的用法示例。


在下文中一共展示了utils.checksum方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_build

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def post_build(self, p, pay):
        p += pay
        dataofs = self.dataofs
        if dataofs is None:
            dataofs = 5+((len(self.get_field("options").i2m(self,self.options))+3)/4)
            p = p[:12]+chr((dataofs << 4) | ord(p[12])&0x0f)+p[13:]
        if self.chksum is None:
            if isinstance(self.underlayer, IP):
                if self.underlayer.len is not None:
                    ln = self.underlayer.len-20
                else:
                    ln = len(p)
                psdhdr = struct.pack("!4s4sHH",
                                     inet_aton(self.underlayer.src),
                                     inet_aton(self.underlayer.dst),
                                     self.underlayer.proto,
                                     ln)
                ck=checksum(psdhdr+p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            elif conf.ipv6_enabled and isinstance(self.underlayer, scapy.layers.inet6.IPv6) or isinstance(self.underlayer, scapy.layers.inet6._IPv6ExtHdr):
                ck = scapy.layers.inet6.in6_chksum(socket.IPPROTO_TCP, self.underlayer, p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            else:
                warning("No IP underlayer to compute checksum. Leaving null.")
        return p 
开发者ID:medbenali,项目名称:CyberScan,代码行数:27,代码来源:inet.py

示例2: post_build

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def post_build(self, p, pay):
        p += pay
        l = self.len
        if l is None:
            l = len(p)
            p = p[:4]+struct.pack("!H",l)+p[6:]
        if self.chksum is None:
            if isinstance(self.underlayer, IP):
                if self.underlayer.len is not None:
                    ln = self.underlayer.len-20
                else:
                    ln = len(p)
                psdhdr = struct.pack("!4s4sHH",
                                     inet_aton(self.underlayer.src),
                                     inet_aton(self.underlayer.dst),
                                     self.underlayer.proto,
                                     ln)
                ck=checksum(psdhdr+p)
                p = p[:6]+struct.pack("!H", ck)+p[8:]
            elif isinstance(self.underlayer, scapy.layers.inet6.IPv6) or isinstance(self.underlayer, scapy.layers.inet6._IPv6ExtHdr):
                ck = scapy.layers.inet6.in6_chksum(socket.IPPROTO_UDP, self.underlayer, p)
                p = p[:6]+struct.pack("!H", ck)+p[8:]
            else:
                warning("No IP underlayer to compute checksum. Leaving null.")
        return p 
开发者ID:Neohapsis,项目名称:mptcp-abuse,代码行数:27,代码来源:inet.py

示例3: post_build

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def post_build(self, p, pay):
        p += pay
        dataofs = self.dataofs
        if dataofs is None:
            dataofs = 5+((len(self.get_field("options").i2m(self,self.options))+3)//4)
            p = p[:12]+bytes([(dataofs << 4) | (p[12])&0x0f])+p[13:]
        if self.chksum is None:
            if isinstance(self.underlayer, IP):
                if self.underlayer.len is not None:
                    ln = self.underlayer.len-20
                else:
                    ln = len(p)
                psdhdr = struct.pack("!4s4sHH",
                                     inet_aton(self.underlayer.src),
                                     inet_aton(self.underlayer.dst),
                                     self.underlayer.proto,
                                     ln)
                ck=checksum(psdhdr+p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            elif conf.ipv6_enabled and isinstance(self.underlayer, scapy.layers.inet6.IPv6) or isinstance(self.underlayer, scapy.layers.inet6._IPv6ExtHdr):
                ck = scapy.layers.inet6.in6_chksum(socket.IPPROTO_TCP, self.underlayer, p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            else:
                warning("No IP underlayer to compute checksum. Leaving null.")
        return p 
开发者ID:entynetproject,项目名称:arissploit,代码行数:27,代码来源:inet.py

示例4: post_build

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def post_build(self, pkt, payload):

        pkt += payload

        # max_resp_code field is reserved (0)
        if self.type in [IGMP_TYPE_V3_MEMBERSHIP_REPORT,]:
            mrc = 0
        else:
            mrc = self.encode_float(self.max_resp_code)
        pkt = pkt[:1] + chr(mrc) + pkt[2:]

        if self.checksum is None:
            chksum = checksum(pkt)
            pkt = pkt[:2] + chr(chksum >> 8) + chr(chksum & 0xff) + pkt[4:]

        return pkt 
开发者ID:opencord,项目名称:voltha,代码行数:18,代码来源:IGMP.py

示例5: post_build

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def post_build(self, pkt, pay):
        if self.chksum == None:
            pkt = pkt[:6] + struct.pack("!H", checksum(pkt)) + pkt[8:]

        return pkt 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:7,代码来源:carp.py

示例6: _recv

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import checksum [as 别名]
def _recv(self, p, x=MTU):
        if p is None:
            return p
        elif isinstance(p, IP):
            # TODO: verify checksum
            if p.src == self.dst and p.proto == socket.IPPROTO_IPV6:
                if isinstance(p.payload, IPv6):
                    return p.payload
        return p 
开发者ID:secdev,项目名称:scapy,代码行数:11,代码来源:inet6.py


注:本文中的scapy.utils.checksum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。