用于与ipstack geo api接口的python库

ipstack的Python项目详细描述


ipstack for python(地理位置库)

IPStack for Python is a simple library used to interface with an IPStack Geo API.

Hint: IPStack for Python is available through Python PIP. pip install ipstack

支持python 2.7+

PyPI versionPyCodeStyleDownloadsGitHub issuesGitHub license

在此处了解有关ipstack的更多信息:ipstack.net

Looking for the PHP version?

功能

  • 检索任何IP地址的地理位置数据。
  • 检索执行此代码的系统的地理位置数据。
  • 检索客户端的地理位置数据。
  • 检索一批IP地址的地理位置数据。
  • 评估IP地址的安全性。

基本用法

fromipstackimportGeoLookupgeo_lookup=GeoLookup(".....")location=geo_lookup.get_location("github.com")print(location)

示例用法

Note: See IPStack: Response Objects for a list of available properties in a response object.

创建geolookup对象
fromipstackimportGeoLookup# Create the GeoLookup object using your API key.geo_lookup=GeoLookup("acecac3893c90871c3")

查找IP地址的位置
# Lookup a location for an IP Address# and catch any exceptions that might# be throwntry:# Retrieve the location information for # github.com by using it's hostname.# # This function will work with hostnames# or IP addresses.location=geo_lookup.get_location("github.com")# If we are unable to retrieve the location information# for an IP address, null will be returned.iflocationisNone:print("Failed to find location.")else:# Print the Location dictionary.print(location)exceptExceptionase:print(e)

查找自己的位置

For looking up your own location we use https://ip.42.pl/raw

location=geo_lookup.get_own_location()print(location)

其他功能

这个库和ipstack api中还内置了一些其他有用的特性。

  1. 批量位置查找

    ipstack api还提供了同时为多个ipv4或ipv6地址请求数据的能力。这需要专业的teir api密钥或更高的密钥,并且一次限制为50个ip。

    See: https://ipstack.com/documentation#bulk

    locations=geo_lookup.get_location("github.com","stackoverflow.com")print(locations)
  2. 请求IP地址的主机名。

    默认情况下,ipstack api不返回有关给定ip地址解析到的主机名的信息。要包含主机名,请使用以下命令。

    See: https://ipstack.com/documentation#hostname

    location=geo_lookup.find_hostname().get_location("1.1.1.1")print(location["hostname"])
    one.one.one.one
    
  3. 评估安全性

    订阅Professional Plus计划的客户可以访问Ipstack API的安全模块,该模块可用于在对网站或Web应用程序造成任何损害之前评估来自某些IP地址的风险和威胁。

    See: https://ipstack.com/documentation#security

    location=geo_lookup.assess_security().get_location("github.com")
  4. 设置响应的语言

    ipstack api能够以不同的语言交付其结果集。要以英语以外的语言(默认)请求数据,请使用以下支持的语言代码之一。

    See: https://ipstack.com/documentation#language

    Supported Langauges

    location=geo_lookup.language("en").get_location("github.com")
  5. 配置您的请求

    # Use HTTPS# This requires IPStack Basic plan or higher.location=geo_lookup.use_https().get_location("github.com")# Configure the timeout for requestslocation=geo_lookup.timeout(10).get_location("github.com")

发展

在提交任何内容之前,请使用以下内容创建预提交挂钩。

这将确保pycodestyle徽章正确更新。

#!/bin/bash
python3 tests/style.py

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar