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


Python utils.inet_aton方法代码示例

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


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

示例1: i2m

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def i2m(self, pkt, x):
        if not x:
            return b""
        if isinstance(x, bytes):
            return x
        s = b"\x01\x00"
        tmp_len = 0
        fec = b""
        for o in x:
            fec += b"\x02\x00\x01"
            # mask length
            fec += struct.pack("!B", o[1])
            # Prefix
            fec += inet_aton(o[0])
            tmp_len += 8
        s += struct.pack("!H", tmp_len)
        s += fec
        return s 
开发者ID:secdev,项目名称:scapy,代码行数:20,代码来源:ldp.py

示例2: build_hmac_sha1

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def build_hmac_sha1(self, pw=b'\x00' * 20, ip4l=[], ip6l=[]):
        h = hmac.new(pw, digestmod=hashlib.sha1)
        # XXX: this is a dirty hack. it needs to pack version and type into a single 8bit field  # noqa: E501
        h.update(b'\x21')
        # XXX: mac addy if different from special link layer. comes before vhid
        h.update(struct.pack('!B', self.vhid))

        sl = []
        for i in ip4l:
            # sort ips from smallest to largest
            sl.append(inet_aton(i))
        sl.sort()

        for i in sl:
            h.update(i)

        # XXX: do ip6l sorting

        return h.digest() 
开发者ID:secdev,项目名称:scapy,代码行数:21,代码来源:carp.py

示例3: enc

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def enc(cls, ipaddr_ascii):
        try:
            s = inet_aton(ipaddr_ascii)
        except Exception:
            raise BER_Encoding_Error("IPv4 address could not be encoded") 
        return chr(cls.tag)+BER_len_enc(len(s))+s 
开发者ID:medbenali,项目名称:CyberScan,代码行数:8,代码来源:ber.py

示例4: getmacbyip

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def getmacbyip(ip, chainCC=0):
    """Return MAC address corresponding to a given IP address"""
    if isinstance(ip,Net):
        ip = iter(ip).next()
    tmp = map(ord, inet_aton(ip))
    if (tmp[0] & 0xf0) == 0xe0: # mcast @
        return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3])
    iff,a,gw = conf.route.route(ip)
    if ( (iff == LOOPBACK_NAME) or (ip == conf.route.get_if_bcast(iff)) ):
        return "ff:ff:ff:ff:ff:ff"
    # Windows uses local IP instead of 0.0.0.0 to represent locally reachable addresses
    ifip = str(pcapdnet.dnet.intf().get(iff)['addr'])
    if gw != ifip.split('/')[0]:
        ip = gw

    mac = conf.netcache.arp_cache.get(ip)
    if mac:
        return mac

    res = srp1(Ether(dst=ETHER_BROADCAST)/ARP(op="who-has", pdst=ip),
               type=ETH_P_ARP,
               iface = iff,
               timeout=2,
               verbose=0,
               chainCC=chainCC,
               nofilter=1)
    if res is not None:
        mac = res.payload.hwsrc
        conf.netcache.arp_cache[ip] = mac
        return mac
    return None 
开发者ID:medbenali,项目名称:CyberScan,代码行数:33,代码来源:__init__.py

示例5: h2i

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def h2i(self, pkt, x):
        if isinstance(x, bytes):
            x = plain_str(x)
        if isinstance(x, str):
            try:
                inet_aton(x)
            except socket.error:
                x = Net(x)
        elif isinstance(x, list):
            x = [self.h2i(pkt, n) for n in x]
        return x 
开发者ID:secdev,项目名称:scapy,代码行数:13,代码来源:fields.py

示例6: i2m

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def i2m(self, pkt, x):
        if x is None:
            return b'\x00\x00\x00\x00'
        return inet_aton(plain_str(x)) 
开发者ID:secdev,项目名称:scapy,代码行数:6,代码来源:fields.py

示例7: __init__

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def __init__(self, name, default, wordbytes=1, length_from=None):
        _IPPrefixFieldBase.__init__(self, name, default, wordbytes, 4, inet_aton, inet_ntoa, length_from)  # noqa: E501 
开发者ID:secdev,项目名称:scapy,代码行数:4,代码来源:fields.py

示例8: enc

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def enc(cls, ipaddr_ascii):
        try:
            s = inet_aton(ipaddr_ascii)
        except Exception:
            raise BER_Encoding_Error("IPv4 address could not be encoded")
        return chb(hash(cls.tag)) + BER_len_enc(len(s)) + s 
开发者ID:secdev,项目名称:scapy,代码行数:8,代码来源:ber.py

示例9: opaqueid

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def opaqueid(self):
        return struct.unpack('>I', inet_aton(self.id))[0] & 0xFFFFFF 
开发者ID:secdev,项目名称:scapy,代码行数:4,代码来源:ospf.py

示例10: opaquetype

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def opaquetype(self):
        return (struct.unpack('>I', inet_aton(self.id))[0] >> 24) & 0xFF 
开发者ID:secdev,项目名称:scapy,代码行数:4,代码来源:ospf.py

示例11: any2i

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def any2i(self, pkt, x):
        if x and isinstance(x, str):
            try:    # Try IPv4 conversion
                s = inet_aton(x)
                return b'\x00\x01' + s
            except BaseException:
                try:    # Try IPv6 conversion
                    s = inet_pton(socket.AF_INET6, x)
                    return b'\x00\x02' + s
                except BaseException:
                    print('Warning: Address format not supported yet.')
        return b'' 
开发者ID:secdev,项目名称:scapy,代码行数:14,代码来源:diameter.py

示例12: enc

# 需要导入模块: from scapy import utils [as 别名]
# 或者: from scapy.utils import inet_aton [as 别名]
def enc(cls, ipaddr_ascii):
        try:
            s = inet_aton(ipaddr_ascii)
        except Exception:
            raise BER_Encoding_Error("IPv4 address could not be encoded") 
        return bytes([hash(cls.tag)])+BER_len_enc(len(s))+s 
开发者ID:entynetproject,项目名称:arissploit,代码行数:8,代码来源:ber.py


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