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

Python util.ip2long函数代码示例

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

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



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

示例1: record_by_addr

    def record_by_addr(self, addr):
        """
        Look up the record for a given IP address.
        Use this method if you have a City database.

        @param addr: IP address
        @type addr: str
        @return: Dictionary with country_code, country_code3, country_name,
            region, city, postal_code, latitude, longitude, dma_code,
            metro_code, area_code, region_name, time_zone
        @rtype: dict
        """
        try:
            ipnum = util.ip2long(addr)
            if not ipnum:
                raise ValueError('Invalid IP address')

            if self._databaseType not in const.CITY_EDITIONS:
                message = 'Invalid database type, expected City'
                raise GeoIPError(message)

            rec = self._get_record(ipnum)
            if not rec:
                return None

            return rec
        except ValueError:
            raise GeoIPError('Failed to lookup address %s' % addr)
开发者ID:colburnhayden,项目名称:pygeoip,代码行数:28,代码来源:__init__.py


示例2: region_by_addr

    def region_by_addr(self, addr):
        """
        Lookup the region for given IP address.
        Use this method if you have a Region database.

        @param addr: IP address
        @type addr: str
        @return: dict containing country_code, region,
            and region_name
        @rtype: dict
        """
        try:
            ipnum = ip2long(addr)

            if not ipnum:
                raise ValueError("Invalid IP address: %s" % addr)

            if not self._databaseType in (const.REGION_EDITION_REV0, const.REGION_EDITION_REV1,
                                          const.CITY_EDITION_REV0, const.CITY_EDITION_REV1):
                raise GeoIPError('Invalid database type; region_* methods expect '\
                                 'Region or City database')

            return self._get_region(ipnum)
        except ValueError:
            raise GeoIPError('*_by_addr methods only accept IP addresses. Use *_by_name for hostnames. (Address: %s)' % addr)
开发者ID:emf,项目名称:pygeoip,代码行数:25,代码来源:__init__.py


示例3: lookup

    def lookup(self, addr):
        addrlong = ip2long(addr)

        data = DictObject()
        data.addr = addr

        for location_ip in LocationIP.objects.all():
            if ((addrlong & ip2long(location_ip.mask)) == ip2long(location_ip.address)):
                location = location_ip.location
                data.latitude = location.latitude
                data.longitude = location.longitude
                data.name = location.name
                match = True
                break

        if match:
            return data
        else:
            return None
开发者ID:carriercomm,项目名称:steelscript-appfwk,代码行数:19,代码来源:geoip.py


示例4: region_by_addr

    def region_by_addr(self, addr):
        """
        Returns dictionary containing `country_code` and `region_code`.

        :arg addr: IP address (e.g. 203.0.113.30)
        """
        if self._databaseType not in const.REGION_CITY_EDITIONS:
            message = 'Invalid database type, expected Region or City'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_region(ipnum)
开发者ID:oschwald,项目名称:pygeoip,代码行数:12,代码来源:__init__.py


示例5: time_zone_by_addr

    def time_zone_by_addr(self, addr):
        """
        Returns time zone in tzdata format (e.g. America/New_York or Europe/Paris)

        :arg addr: IP address (e.g. 203.0.113.30)
        """
        if self._databaseType not in const.CITY_EDITIONS:
            message = 'Invalid database type, expected City'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_record(ipnum).get('time_zone')
开发者ID:oschwald,项目名称:pygeoip,代码行数:12,代码来源:__init__.py


示例6: org_by_addr

    def org_by_addr(self, addr):
        """
        Returns Organization, ISP, or ASNum name for given IP address.

        :arg addr: IP address (e.g. 203.0.113.30)
        """
        valid = (const.ORG_EDITION, const.ISP_EDITION, const.ASNUM_EDITION, const.ASNUM_EDITION_V6)
        if self._databaseType not in valid:
            message = 'Invalid database type, expected Org, ISP or ASNum'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_org(ipnum)
开发者ID:oschwald,项目名称:pygeoip,代码行数:13,代码来源:__init__.py


示例7: netspeed_by_addr

    def netspeed_by_addr(self, addr):
        """
        Returns NetSpeed name from address.

        :arg addr: IP address (e.g. 203.0.113.30)
        """
        if self._databaseType == const.NETSPEED_EDITION:
            return const.NETSPEED_NAMES[self.id_by_addr(addr)]
        elif self._databaseType in (const.NETSPEED_EDITION_REV1,
                                    const.NETSPEED_EDITION_REV1_V6):
            ipnum = util.ip2long(addr)
            return self._get_org(ipnum)

        raise GeoIPError(
            'Invalid database type, expected NetSpeed or NetSpeedCell')
开发者ID:Architektor,项目名称:PySnip,代码行数:15,代码来源:__init__.py


示例8: id_by_addr

    def id_by_addr(self, addr):
        """
        Returns the database ID for specified address.
        The ID might be useful as array index. 0 is unknown.

        :arg addr: IPv4 or IPv6 address (eg. 203.0.113.30)
        """
        ipv = 6 if addr.find(":") >= 0 else 4
        if ipv == 4 and self._databaseType not in (const.COUNTRY_EDITION, const.NETSPEED_EDITION):
            raise GeoIPError("Invalid database type; expected IPv6 address")
        if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
            raise GeoIPError("Invalid database type; expected IPv4 address")

        ipnum = util.ip2long(addr)
        return self._seek_country(ipnum) - const.COUNTRY_BEGIN
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:15,代码来源:__init__.py


示例9: lookup

    def lookup(self, addr):
        data = DictObject()
        data.addr = addr
        data.internal = False

        with lookup_lock:
            r = self.geoip.record_by_addr(addr)

        match = False

        if r is not None:
            data.latitude = r['latitude']
            data.longitude = r['longitude']
            match = True
            try:
                (n, x, y) = socket.gethostbyaddr(addr)
                data.name = n
            except:
                data.name = None

        else:
            addrlong = ip2long(addr)
            
            for location in Location.objects.all():
                if ((addrlong & ip2long(location.mask)) == ip2long(location.address)):
                    data.latitude = location.latitude
                    data.longitude = location.longitude
                    data.name = location.name
                    data.internal = True
                    match = True
                    break

        if match:
            return data
        else:
            return None
开发者ID:Playithealth,项目名称:flyscript-portal,代码行数:36,代码来源:geoip.py


示例10: time_zone_by_addr

    def time_zone_by_addr(self, addr):
        """
        Look up the time zone for a given IP address.
        Use this method if you have a Region or City database.

        @param addr: IP address
        @type addr: str
        @return: Time zone
        @rtype: str
        """
        if self._databaseType not in const.CITY_EDITIONS:
            message = 'Invalid database type, expected City'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_record(ipnum).get('time_zone')
开发者ID:muhdammar92,项目名称:pygeoip,代码行数:16,代码来源:__init__.py


示例11: region_by_addr

    def region_by_addr(self, addr):
        """
        Lookup the region for given IP address.
        Use this method if you have a Region database.

        @param addr: IP address
        @type addr: str
        @return: Dictionary containing country_code and region_code
        @rtype: dict
        """
        if self._databaseType not in const.REGION_CITY_EDITIONS:
            message = 'Invalid database type, expected Region or City'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_region(ipnum)
开发者ID:muhdammar92,项目名称:pygeoip,代码行数:16,代码来源:__init__.py


示例12: id_by_addr

    def id_by_addr(self, addr):
        """
        Returns the database ID for specified address.
        The ID might be useful as array index. 0 is unknown.

        :arg addr: IPv4 or IPv6 address (eg. 203.0.113.30)
        """
        if self._databaseType in (const.PROXY_EDITION, const.NETSPEED_EDITION_REV1, const.NETSPEED_EDITION_REV1_V6):
            raise GeoIPError('Invalid database type; this database is not supported')
        ipv = 6 if addr.find(':') >= 0 else 4
        if ipv == 4 and self._databaseType not in (const.COUNTRY_EDITION, const.NETSPEED_EDITION):
            raise GeoIPError('Invalid database type; this database supports IPv6 addresses, not IPv4')
        if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
            raise GeoIPError('Invalid database type; this database supports IPv4 addresses, not IPv6')

        ipnum = util.ip2long(addr)
        return self._seek_country(ipnum) - const.COUNTRY_BEGIN
开发者ID:oschwald,项目名称:pygeoip,代码行数:17,代码来源:__init__.py


示例13: org_by_addr

    def org_by_addr(self, addr):
        """
        Lookup Organization, ISP or ASNum for given IP address.
        Use this method if you have an Organization, ISP or ASNum database.

        @param addr: IP address
        @type addr: str
        @return: organization or ISP name
        @rtype: str
        """
        valid = (const.ORG_EDITION, const.ISP_EDITION, const.ASNUM_EDITION, const.ASNUM_EDITION_V6)
        if self._databaseType not in valid:
            message = 'Invalid database type, expected Org, ISP or ASNum'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        return self._get_org(ipnum)
开发者ID:muhdammar92,项目名称:pygeoip,代码行数:17,代码来源:__init__.py


示例14: record_by_addr

    def record_by_addr(self, addr):
        """
        Returns dictionary with city data containing `country_code`, `country_name`,
        `region`, `city`, `postal_code`, `latitude`, `longitude`, `dma_code`,
        `metro_code`, `area_code`, `region_code` and `time_zone`.

        :arg addr: IP address (e.g. 203.0.113.30)
        """
        if self._databaseType not in const.CITY_EDITIONS:
            message = 'Invalid database type, expected City'
            raise GeoIPError(message)

        ipnum = util.ip2long(addr)
        rec = self._get_record(ipnum)
        if not rec:
            return None

        return rec
开发者ID:oschwald,项目名称:pygeoip,代码行数:18,代码来源:__init__.py


示例15: _id_by_addr

    def _id_by_addr(self, addr):
        """
        Looks up the index for the country which is the key for the
        code and name.

        @param addr: IPv4 or IPv6 address
        @type addr: str
        @return: network byte order 32-bit integer
        @rtype: int
        """
        ipv = 6 if addr.find(':') >= 0 else 4
        if ipv == 4 and self._databaseType != const.COUNTRY_EDITION:
            raise GeoIPError('Invalid database type; expected IPv6 address')
        if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
            raise GeoIPError('Invalid database type; expected IPv4 address')

        ipnum = util.ip2long(addr)
        return self._seek_country(ipnum) - const.COUNTRY_BEGIN
开发者ID:muhdammar92,项目名称:pygeoip,代码行数:18,代码来源:__init__.py


示例16: id_by_addr

    def id_by_addr(self, addr):
        """
        Returns the database id for specified address.
        The id might be useful as array index. 0 is unknown.

        @param addr: IPv4 or IPv6 address
        @type addr: str
        @return: network byte order 32-bit integer
        @rtype: int
        """
        ipv = 6 if addr.find(':') >= 0 else 4
        if ipv == 4 and self._databaseType not in (const.COUNTRY_EDITION, const.NETSPEED_EDITION):
            raise GeoIPError('Invalid database type; expected IPv6 address')
        if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
            raise GeoIPError('Invalid database type; expected IPv4 address')

        ipnum = util.ip2long(addr)
        return self._seek_country(ipnum) - const.COUNTRY_BEGIN
开发者ID:elaineo,项目名称:barnacle-gae,代码行数:18,代码来源:__init__.py


示例17: id_by_addr

    def id_by_addr(self, addr):
        """
        Get the country index.
        Looks up the index for the country which is the key for
        the code and name.

        @param addr: The IP address
        @type addr: str
        @return: network byte order 32-bit integer
        @rtype: int
        """
        ipnum = util.ip2long(addr)
        if not ipnum:
            raise ValueError("Invalid IP address: %s" % addr)

        COUNTY_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6)
        if self._databaseType not in COUNTY_EDITIONS:
            message = 'Invalid database type, expected Country'
            raise GeoIPError(message)

        return self._seek_country(ipnum) - const.COUNTRY_BEGIN
开发者ID:Khan,项目名称:pygeoip,代码行数:21,代码来源:__init__.py


示例18: region_by_addr

    def region_by_addr(self, addr):
        """
        Lookup the region for given IP address.
        Use this method if you have a Region database.

        @param addr: IP address
        @type addr: str
        @return: Dictionary containing country_code, region and region_name
        @rtype: dict
        """
        try:
            ipnum = util.ip2long(addr)
            if not ipnum:
                raise ValueError('Invalid IP address')

            if self._databaseType not in const.REGION_CITY_EDITIONS:
                message = 'Invalid database type, expected Region or City'
                raise GeoIPError(message)

            return self._get_region(ipnum)
        except ValueError:
            raise GeoIPError('Failed to lookup address %s' % addr)
开发者ID:Khan,项目名称:pygeoip,代码行数:22,代码来源:__init__.py


示例19: time_zone_by_addr

    def time_zone_by_addr(self, addr):
        """
        Look up the time zone for a given IP address.
        Use this method if you have a Region or City database.

        @param addr: IP address
        @type addr: str
        @return: Time zone
        @rtype: str
        """
        try:
            ipnum = util.ip2long(addr)
            if not ipnum:
                raise ValueError('Invalid IP address')

            if self._databaseType not in const.CITY_EDITIONS:
                message = 'Invalid database type, expected City'
                raise GeoIPError(message)

            return self._get_record(ipnum)['time_zone']
        except ValueError:
            raise GeoIPError('Failed to lookup address %s' % addr)
开发者ID:Asinox,项目名称:pygeoip,代码行数:22,代码来源:__init__.py


示例20: org_by_addr

    def org_by_addr(self, addr):
        """
        Lookup Organization, ISP or ASNum for given IP address.
        Use this method if you have an Organization, ISP or ASNum database.

        @param addr: IP address
        @type addr: str
        @return: organization or ISP name
        @rtype: str
        """
        try:
            ipnum = util.ip2long(addr)
            if not ipnum:
                raise ValueError("Invalid IP address")

            valid = (const.ORG_EDITION, const.ISP_EDITION, const.ASNUM_EDITION)
            if self._databaseType not in valid:
                message = "Invalid database type, expected Org, ISP or ASNum"
                raise GeoIPError(message)

            return self._get_org(ipnum)
        except ValueError:
            raise GeoIPError("Failed to lookup address %s" % addr)
开发者ID:cesarbruschetta,项目名称:django-in-gae,代码行数:23,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python kegg.Kegg类代码示例发布时间:2022-05-25
下一篇:
Python pygeoip.GeoIP类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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