• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.atol函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _read_routes_xp

def _read_routes_xp():
    # The InterfaceIndex in Win32_IP4RouteTable does not match the
    # InterfaceIndex in Win32_NetworkAdapter under some platforms
    # (namely Windows XP): let's try an IP association
    routes = []
    partial_routes = []
    # map local IP addresses to interfaces
    local_addresses = {iface.ip: iface for iface in six.itervalues(IFACES)}
    iface_indexes = {}
    for line in exec_query(['Get-WmiObject', 'Win32_IP4RouteTable'],
                           ['Name', 'Mask', 'NextHop', 'InterfaceIndex', 'Metric1']):
        if line[2] in local_addresses:
            iface = local_addresses[line[2]]
            # This gives us an association InterfaceIndex <-> interface
            iface_indexes[line[3]] = iface
            routes.append((atol(line[0]), atol(line[1]), "0.0.0.0", iface,
                           iface.ip, int(line[4])))
        else:
            partial_routes.append((atol(line[0]), atol(line[1]), line[2],
                                   line[3], int(line[4])))
    for dst, mask, gw, ifidx, metric in partial_routes:
        if ifidx in iface_indexes:
            iface = iface_indexes[ifidx]
            routes.append((dst, mask, gw, iface, iface.ip, metric))
    return routes
开发者ID:dark-lbp,项目名称:scapy,代码行数:25,代码来源:__init__.py


示例2: read_routes_7

def read_routes_7():
    routes = []
    for line in exec_query(["Get-WmiObject", "win32_IP4RouteTable"], ["Name", "Mask", "NextHop", "InterfaceIndex"]):
        try:
            iface = dev_from_index(line[3])
        except ValueError:
            continue
        routes.append((atol(line[0]), atol(line[1]), line[2], iface, iface.ip))
    return routes
开发者ID:guedou,项目名称:scapy-issues,代码行数:9,代码来源:__init__.py


示例3: read_routes_7

def read_routes_7():
    routes=[]
    for line in exec_query(['Get-WmiObject', 'win32_IP4RouteTable'],
                           ['Name', 'Mask', 'NextHop', 'InterfaceIndex']):
        try:
            iface = dev_from_index(line[3])
        except ValueError:
            continue
        routes.append((atol(line[0]), atol(line[1]), line[2], iface, iface.ip))
    return routes
开发者ID:secdev,项目名称:scapy,代码行数:10,代码来源:__init__.py


示例4: _read_routes_7

def _read_routes_7():
    routes=[]
    for line in exec_query(['Get-WmiObject', 'Win32_IP4RouteTable'],
                           ['Name', 'Mask', 'NextHop', 'InterfaceIndex', 'Metric1']):
        try:
            iface = dev_from_index(line[3])
            ip = "127.0.0.1" if line[3] == "1" else iface.ip # Force loopback on iface 1
            routes.append((atol(line[0]), atol(line[1]), line[2], iface, ip, int(line[4])))
        except ValueError:
            continue
    return routes
开发者ID:dark-lbp,项目名称:scapy,代码行数:11,代码来源:__init__.py


示例5: route

    def route(self, dst=None, verbose=conf.verb):
        """Returns the IPv4 routes to a host.
        parameters:
         - dst: the IPv4 of the destination host

        returns: (iface, output_ip, gateway_ip)
         - iface: the interface used to connect to the host
         - output_ip: the outgoing IP that will be used
         - gateway_ip: the gateway IP that will be used
        """
        dst = dst or "0.0.0.0"  # Enable route(None) to return default route
        if isinstance(dst, bytes):
            try:
                dst = plain_str(dst)
            except UnicodeDecodeError:
                raise TypeError("Unknown IP address input (bytes)")
        if dst in self.cache:
            return self.cache[dst]
        # Transform "192.168.*.1-5" to one IP of the set
        _dst = dst.split("/")[0].replace("*", "0")
        while True:
            idx = _dst.find("-")
            if idx < 0:
                break
            m = (_dst[idx:] + ".").find(".")
            _dst = _dst[:idx] + _dst[idx + m:]

        atol_dst = atol(_dst)
        paths = []
        for d, m, gw, i, a, me in self.routes:
            if not a:  # some interfaces may not currently be connected
                continue
            aa = atol(a)
            if aa == atol_dst:
                paths.append(
                    (0xffffffff, 1, (scapy.consts.LOOPBACK_INTERFACE, a, "0.0.0.0"))  # noqa: E501
                )
            if (atol_dst & m) == (d & m):
                paths.append((m, me, (i, a, gw)))

        if not paths:
            if verbose:
                warning("No route found (no default route?)")
            return scapy.consts.LOOPBACK_INTERFACE, "0.0.0.0", "0.0.0.0"
        # Choose the more specific route
        # Sort by greatest netmask and use metrics as a tie-breaker
        paths.sort(key=lambda x: (-x[0], x[1]))
        # Return interface
        ret = paths[0][2]
        self.cache[dst] = ret
        return ret
开发者ID:commial,项目名称:scapy,代码行数:51,代码来源:route.py


示例6: route

    def route(self, dest, verbose=None):
        if dest is None:
            dest = "0.0.0.0"
        elif isinstance(dest, bytes):
            try:
                dest = plain_str(dest)
            except UnicodeDecodeError:
                dest = "0.0.0.0"
        if dest in self.cache:
            return self.cache[dest]
        if verbose is None:
            verbose = conf.verb
        # Transform "192.168.*.1-5" to one IP of the set
        dst = dest.split("/")[0]
        dst = dst.replace("*", "0")
        while True:
            l = dst.find("-")
            if l < 0:
                break
            m = (dst[l:] + ".").find(".")
            dst = dst[:l] + dst[l + m:]

        dst = atol(dst)
        pathes = []
        for d, m, gw, i, a, me in self.routes:
            if not a:  # some interfaces may not currently be connected
                continue
            aa = atol(a)
            if aa == dst:
                pathes.append(
                    (0xffffffff, 1, (scapy.consts.LOOPBACK_INTERFACE, a, "0.0.0.0"))  # noqa: E501
                )
            if (dst & m) == (d & m):
                pathes.append((m, me, (i, a, gw)))
        if not pathes:
            if verbose:
                warning("No route found (no default route?)")
            return scapy.consts.LOOPBACK_INTERFACE, "0.0.0.0", "0.0.0.0"
        # Choose the more specific route
        # Sort by greatest netmask
        pathes.sort(key=lambda x: x[0], reverse=True)
        # Get all pathes having the (same) greatest mask
        pathes = [i for i in pathes if i[0] == pathes[0][0]]
        # Tie-breaker: Metrics
        pathes.sort(key=lambda x: x[1])
        # Return interface
        ret = pathes[0][2]
        self.cache[dest] = ret
        return ret
开发者ID:plorinquer,项目名称:scapy,代码行数:49,代码来源:route.py


示例7: _read_routes_post2008

def _read_routes_post2008():
    routes = []
    if4_metrics = None
    # This works only starting from Windows 8/2012 and up. For older Windows another solution is needed
    # Get-NetRoute -AddressFamily IPV4 | select ifIndex, DestinationPrefix, NextHop, RouteMetric, InterfaceMetric | fl
    for line in exec_query(['Get-NetRoute', '-AddressFamily IPV4'], ['ifIndex', 'DestinationPrefix', 'NextHop', 'RouteMetric', 'InterfaceMetric']):
        try:
            iface = dev_from_index(line[0])
            if iface.ip == "0.0.0.0":
                continue
        except:
            continue
        # try:
        #     intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
        # except OSError:
        #     log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s", dest)
        #     continue
        dest, mask = line[1].split('/')
        ip = "127.0.0.1" if line[0] == "1" else iface.ip # Force loopback on iface 1
        if not line[4].strip():  # InterfaceMetric is not available. Load it from netsh
            if not if4_metrics:
                 if4_metrics = _get_metrics()
            metric = int(line[3]) + if4_metrics.get(iface.win_index, 0)  # RouteMetric + InterfaceMetric
        else:
            metric = int(line[3]) + int(line[4])  # RouteMetric + InterfaceMetric
        routes.append((atol(dest), itom(int(mask)),
                       line[2], iface, ip, metric))
    return routes
开发者ID:martingalloar,项目名称:scapy,代码行数:28,代码来源:__init__.py


示例8: read_routes_post2008

def read_routes_post2008():
    # XXX TODO: FIX THIS XXX
    routes = []
    if_index = '(\d+)'
    dest = '(\d+\.\d+\.\d+\.\d+)/(\d+)'
    next_hop = '(\d+\.\d+\.\d+\.\d+)'
    metric_pattern = "(\d+)"
    delim = "\s+"        # The columns are separated by whitespace
    netstat_line = delim.join([if_index, dest, next_hop, metric_pattern])
    pattern = re.compile(netstat_line)
    # This works only starting from Windows 8/2012 and up. For older Windows another solution is needed
    ps = sp.Popen([conf.prog.powershell, 'Get-NetRoute', '-AddressFamily IPV4', '|', 'select ifIndex, DestinationPrefix, NextHop, RouteMetric'], stdout = sp.PIPE, universal_newlines = True)
    stdout, stdin = ps.communicate()
    for l in stdout.split('\n'):
        match = re.search(pattern,l)
        if match:
            try:
                iface = dev_from_index(match.group(1))
            except:
                continue
            # try:
            #     intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
            # except OSError:
            #     log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
            #     continue               
            routes.append((atol(match.group(2)), itom(int(match.group(3))),
                           match.group(4), iface, iface.ip))
    return routes
开发者ID:secdev,项目名称:scapy,代码行数:28,代码来源:__init__.py


示例9: ifadd

 def ifadd(self, iff, addr):
     self.invalidate_cache()
     the_addr,the_msk = (addr.split("/")+["32"])[:2]
     the_msk = itom(int(the_msk))
     the_rawaddr = atol(the_addr)
     the_net = the_rawaddr & the_msk
     self.routes.append((the_net,the_msk,'0.0.0.0',iff,the_addr))
开发者ID:guedou,项目名称:scapy-issues,代码行数:7,代码来源:route.py


示例10: get_if_bcast

 def get_if_bcast(self, iff):
     for net, msk, gw, iface, addr in self.routes:
         if (iff == iface and net != 0):
             bcast = atol(addr) | (~msk & 0xffffffff)
             # FIXME: check error in atol()
             return ltoa(bcast)
     warning("No broadcast address found for iface %s\n" % iff)
开发者ID:cisco-system-traffic-generator,项目名称:trex-core,代码行数:7,代码来源:route.py


示例11: read_routes

def read_routes():
    routes = []
    if_index = '(\d+)'
    dest = '(\d+\.\d+\.\d+\.\d+)/(\d+)'
    next_hop = '(\d+\.\d+\.\d+\.\d+)'
    metric_pattern = "(\d+)"
    delim = "\s+"        # The columns are separated by whitespace
    netstat_line = delim.join([if_index, dest, next_hop, metric_pattern])
    pattern = re.compile(netstat_line)
    ps = sp.Popen(['powershell', 'Get-NetRoute', '-AddressFamily IPV4', '|', 'select ifIndex, DestinationPrefix, NextHop, RouteMetric'], stdout = sp.PIPE, universal_newlines = True)
    stdout, stdin = ps.communicate(timeout = 10)
    for l in stdout.split('\n'):
        match = re.search(pattern,l)
        if match:
            try:
                iface = devname_from_index(int(match.group(1)))
                addr = ifaces[iface].ip
            except:
                continue
            dest = atol(match.group(2))
            mask = itom(int(match.group(3)))
            gw = match.group(4)
            # try:
            #     intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
            # except OSError:
            #     log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
            #     continue               
            routes.append((dest, mask, gw, iface, addr))
    return routes
开发者ID:ouje,项目名称:scapy,代码行数:29,代码来源:__init__.py


示例12: read_routes

def read_routes():
    ok = 0
    routes = []
    ip = "(\d+\.\d+\.\d+\.\d+)"
    # On Vista and Windows 7 the gateway can be IP or 'On-link'.
    # But the exact 'On-link' string depends on the locale, so we allow any text.
    gw_pattern = "(.+)"
    metric_pattern = "(\d+)"
    delim = "\s+"  # The columns are separated by whitespace
    netstat_line = delim.join([ip, ip, gw_pattern, ip, metric_pattern])
    pattern = re.compile(netstat_line)
    f = os.popen("netstat -rn")
    for l in f.readlines():
        match = re.search(pattern, l)
        if match:
            dest = match.group(1)
            mask = match.group(2)
            gw = match.group(3)
            netif = match.group(4)
            metric = match.group(5)
            try:
                intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
            except OSError:
                log_loading.warning(
                    "Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest
                )
                continue
            if not intf.has_key("addr"):
                break
            addr = str(intf["addr"])
            addr = addr.split("/")[0]

            dest = atol(dest)
            mask = atol(mask)
            # If the gateway is no IP we assume it's on-link
            gw_ipmatch = re.search("\d+\.\d+\.\d+\.\d+", gw)
            if gw_ipmatch:
                gw = gw_ipmatch.group(0)
            else:
                gw = netif
            routes.append((dest, mask, gw, str(intf["name"]), addr))
    f.close()
    return routes
开发者ID:0x0mar,项目名称:zarp,代码行数:43,代码来源:__init__.py


示例13: parse_options

 def parse_options(self, pool=Net("192.168.1.128/25"), network="192.168.1.0/24", gw="192.168.1.1",  # noqa: E501
                   domain="localnet", renewal_time=60, lease_time=1800):
     self.domain = domain
     netw, msk = (network.split("/") + ["32"])[:2]
     msk = itom(int(msk))
     self.netmask = ltoa(msk)
     self.network = ltoa(atol(netw) & msk)
     self.broadcast = ltoa(atol(self.network) | (0xffffffff & ~msk))
     self.gw = gw
     if isinstance(pool, six.string_types):
         pool = Net(pool)
     if isinstance(pool, Iterable):
         pool = [k for k in pool if k not in [gw, self.network, self.broadcast]]  # noqa: E501
         pool.reverse()
     if len(pool) == 1:
         pool, = pool
     self.pool = pool
     self.lease_time = lease_time
     self.renewal_time = renewal_time
     self.leases = {}
开发者ID:commial,项目名称:scapy,代码行数:20,代码来源:dhcp.py


示例14: get_if_bcast

 def get_if_bcast(self, iff):
     for net, msk, gw, iface, addr, metric in self.routes:
         if net == 0:
             continue
         if scapy.consts.WINDOWS:
             if iff.guid != iface.guid:
                 continue
         elif iff != iface:
             continue
         bcast = atol(addr) | (~msk & 0xffffffff)  # FIXME: check error in atol()  # noqa: E501
         return ltoa(bcast)
     warning("No broadcast address found for iface %s\n", iff)
开发者ID:plorinquer,项目名称:scapy,代码行数:12,代码来源:route.py


示例15: get_if_bcast

 def get_if_bcast(self, iff):
     for net, msk, gw, iface, addr in self.routes:
         if net == 0:
             continue
         if WINDOWS:
             if iff.guid != iface.guid:
                 continue
         elif iff != iface:
             continue
         bcast = atol(addr)|(~msk&0xffffffff); # FIXME: check error in atol()
         return ltoa(bcast)
     warning("No broadcast address found for iface %s\n" % iff);
开发者ID:mcpat,项目名称:scapy,代码行数:12,代码来源:route.py


示例16: read_routes_xp

def read_routes_xp():
    # The InterfaceIndex in Win32_IP4RouteTable does not match the
    # InterfaceIndex in Win32_NetworkAdapter under some platforms
    # (namely Windows XP): let's try an IP association
    routes = []
    partial_routes = []
    # map local IP addresses to interfaces
    local_addresses = dict((iface.ip, iface) for iface in IFACES.itervalues())
    iface_indexes = {}
    for line in exec_query(["Get-WmiObject", "Win32_IP4RouteTable"], ["Name", "Mask", "NextHop", "InterfaceIndex"]):
        if line[2] in local_addresses:
            iface = local_addresses[line[2]]
            # This gives us an association InterfaceIndex <-> interface
            iface_indexes[line[3]] = iface
            routes.append((atol(line[0]), atol(line[1]), "0.0.0.0", iface, iface.ip))
        else:
            partial_routes.append((atol(line[0]), atol(line[1]), line[2], line[3]))
    for dst, mask, gw, ifidx in partial_routes:
        if ifidx in iface_indexes:
            iface = iface_indexes[ifidx]
            routes.append((dst, mask, gw, iface, iface.ip))
    return routes
开发者ID:guedou,项目名称:scapy-issues,代码行数:22,代码来源:__init__.py


示例17: route

    def route(self,dest,verbose=None):
        if isinstance(dest, list) and dest:
            dest = dest[0]
        if dest in self.cache:
            return self.cache[dest]
        if verbose is None:
            verbose=conf.verb
        # Transform "192.168.*.1-5" to one IP of the set
        dst = dest.split("/")[0]
        dst = dst.replace("*","0") 
        while True:
            l = dst.find("-")
            if l < 0:
                break
            m = (dst[l:]+".").find(".")
            dst = dst[:l]+dst[l+m:]

            
        dst = atol(dst)
        pathes=[]
        for d,m,gw,i,a in self.routes:
            if not a: # some interfaces may not currently be connected
                continue
            aa = atol(a)
            if aa == dst:
                pathes.append((0xffffffff,(LOOPBACK_INTERFACE,a,"0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m,(i,a,gw)))
        if not pathes:
            if verbose:
                warning("No route found (no default route?)")
            return LOOPBACK_INTERFACE,"0.0.0.0","0.0.0.0"
        # Choose the more specific route (greatest netmask).
        # XXX: we don't care about metrics
        pathes.sort()
        ret = pathes[-1][1]
        self.cache[dest] = ret
        return ret
开发者ID:mcpat,项目名称:scapy,代码行数:38,代码来源:route.py


示例18: route

    def route(self,dest,verbose=None):
        if type(dest) is list and dest:
            dest = dest[0]
        if dest in self.cache:
            return self.cache[dest]
        if verbose is None:
            verbose=conf.verb
        # Transform "192.168.*.1-5" to one IP of the set
        dst = dest.split("/")[0]
        dst = dst.replace("*","0") 
        while True:
            l = dst.find("-")
            if l < 0:
                break
            m = (dst[l:]+".").find(".")
            dst = dst[:l]+dst[l+m:]

            
        dst = atol(dst)
        pathes=[]
        for d,m,gw,i,a in self.routes:
            aa = atol(a)
            #Commented out after issue with virtual network with local address 0.0.0.0
            #if aa == dst:
            #    pathes.append((0xffffffff,(LOOPBACK_NAME,a,"0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m,(i,a,gw)))
        if not pathes:
            if verbose:
                warning("No route found (no default route?)")
            return LOOPBACK_NAME,"0.0.0.0","0.0.0.0" #XXX linux specific!
        # Choose the more specific route (greatest netmask).
        # XXX: we don't care about metrics
        pathes.sort()
        ret = pathes[-1][1]
        self.cache[dest] = ret
        return ret
开发者ID:Pojen-Huang,项目名称:trex-core,代码行数:37,代码来源:route.py


示例19: ifchange

    def ifchange(self, iff, addr):
        self.invalidate_cache()
        the_addr, the_msk = (addr.split("/") + ["32"])[:2]
        the_msk = itom(int(the_msk))
        the_rawaddr = atol(the_addr)
        the_net = the_rawaddr & the_msk

        for i in range(len(self.routes)):
            net, msk, gw, iface, addr = self.routes[i]
            if iface != iff:
                continue
            if gw == '0.0.0.0':
                self.routes[i] = (the_net, the_msk, gw, iface, the_addr)
            else:
                self.routes[i] = (net, msk, gw, iface, the_addr)
        conf.netcache.flush()
开发者ID:cisco-system-traffic-generator,项目名称:trex-core,代码行数:16,代码来源:route.py


示例20: ifchange

    def ifchange(self, iff, addr):
        self.invalidate_cache()
        the_addr, the_msk = (addr.split("/") + ["32"])[:2]
        the_msk = itom(int(the_msk))
        the_rawaddr = atol(the_addr)
        the_net = the_rawaddr & the_msk

        for i, route in enumerate(self.routes):
            net, msk, gw, iface, addr, metric = route
            if scapy.consts.WINDOWS:
                if iff.guid != iface.guid:
                    continue
            elif iff != iface:
                continue
            if gw == '0.0.0.0':
                self.routes[i] = (the_net, the_msk, gw, iface, the_addr, metric)  # noqa: E501
            else:
                self.routes[i] = (net, msk, gw, iface, the_addr, metric)
        conf.netcache.flush()
开发者ID:plorinquer,项目名称:scapy,代码行数:19,代码来源:route.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.warning函数代码示例发布时间:2022-05-27
下一篇:
Python supersocket.SuperSocket类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap