All Projects → xin053 → ipd

xin053 / ipd

Licence: MIT license
查询ip地理信息,多种查询模式,高效,具有缓存机制,并可使用elasticsearch构建自己的ip数据库

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to ipd

Geolocate-IP-Browser-Extension
A browser extension, which shows you the origin of your IP address.
Stars: ✭ 21 (-12.5%)
Mutual labels:  ip
popcat-echo
The server-side reproduction, similar the one of https://popcat.click, improve the performance and speed.
Stars: ✭ 62 (+158.33%)
Mutual labels:  gin
locus
MMDB reader for geolocation and ASN lookup of IP addresses
Stars: ✭ 93 (+287.5%)
Mutual labels:  geolite2
gapp
go gin应用
Stars: ✭ 42 (+75%)
Mutual labels:  gin
botanalyse
botsonar analyse open api
Stars: ✭ 19 (-20.83%)
Mutual labels:  ip
website
Official website and document for Gin
Stars: ✭ 88 (+266.67%)
Mutual labels:  gin
easy-gin
一套基于 Gin 框架的 MVC 脚手架,使用 govendor 包管理
Stars: ✭ 74 (+208.33%)
Mutual labels:  gin
iam
企业级的 Go 语言实战项目:认证和授权系统
Stars: ✭ 1,900 (+7816.67%)
Mutual labels:  gin
hpay
a personal payment applet implemented using the gin framework
Stars: ✭ 71 (+195.83%)
Mutual labels:  gin
short
URL shortening service. 高性能短链接服务。
Stars: ✭ 14 (-41.67%)
Mutual labels:  gin
covid19-kerala-api-deprecated
Deprecated - A fast API service for retrieving day to day stats about Coronavirus(COVID-19, SARS-CoV-2) outbreak in Kerala(India).
Stars: ✭ 14 (-41.67%)
Mutual labels:  gin
pagoda
Ansible API component of Wise2C Breeze project
Stars: ✭ 13 (-45.83%)
Mutual labels:  gin
patent client
A collection of ORM-style clients to public patent data
Stars: ✭ 14 (-41.67%)
Mutual labels:  ip
portakal
Bulk port checker written with Go
Stars: ✭ 18 (-25%)
Mutual labels:  ip
ip
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.
Stars: ✭ 212 (+783.33%)
Mutual labels:  ip
FGRoute
Get your device ip address, router ip or wifi ssid
Stars: ✭ 128 (+433.33%)
Mutual labels:  ip
FreeGithub
😊自动获取github相关网站的ip地址,解决github链接不畅通的问题
Stars: ✭ 45 (+87.5%)
Mutual labels:  ip
Ip
🌏根据IpV4、IpV6地址获取定位信息的PHP🐘组件 PHP components that obtain location information based on IpV4, IpV6 addresses
Stars: ✭ 23 (-4.17%)
Mutual labels:  ip
Aggregator
A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.
Stars: ✭ 19 (-20.83%)
Mutual labels:  ip
Nali
🔧 An IP Geolocation Lookup Utils
Stars: ✭ 16 (-33.33%)
Mutual labels:  qqwry

ipd

批量ip反查服务, 批量获取ip的地理位置信息,包括国家,省份,城市,ISP以及地理位置,支持国内外ip,目前仅支持ipv4.

基于gin框架构建, 默认端口6789,可在config.toml中修改服务端口以及其他配置项

从源代码构建

  1. 下载包管理器dep

    go get -u github.com/golang/dep/cmd/dep

    确保dep在环境变量PATH

  2. 下载ipd源码

    export GOPATH=`pwd`
    go get -d github.com/golang/xin053/ipd
  3. 安装依赖

    dep ensure
  4. 构建ipd可执行文件

    cd github.com/golang/xin053/ipd
    go build ipd.go

    或者

    go build -ldflags "-w -s" ipd.go
  5. 使用

    # 运行
    ./ipd
    # 停止
    kill -2 pid

使用

ipd提供四种ip反查的方式:

  1. 通过纯真ip数据库(目前更新到2018-09-25)

    纯真ip数据库官网,下载可能需要翻墙,下载后安装会释放出qqwry.dat文件,也可以使用 UniExtract2 直接解压出文件

  2. 通过GeoLite2数据库

  3. 通过ip2region数据库,启动服务时会自动从github下载最新的数据库文件(最优先)

  4. 通过公开的 REST API方式, 目前支持四种接口:

    1. 淘宝ip查询接口:http://ip.taobao.com/service/getIpInfo.php?ip=
    2. 新浪ip查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=
    3. 太平洋ip查询接口:http://whois.pconline.com.cn/ipJson.jsp?ip=
    4. 百度ip查询接口:http://api.map.baidu.com/location/ip?ak=yourAK&ip=

API

  1. 从公共API获取ip信息

    接口

    POST /v1/api

    请求头

    1. Authorization = thisisaveryimportantkey(key可在config.go中配置)
    2. Content-Type = application/json

    Body

    {
        "ip":
            ["111.111.111.111", "8.8.8.8"]
    }

    返回

    [
        {
            "ip": "8.8.8.8",
            "country": "美国",
            "region": "",
            "city": "",
            "isp": "Google公共DNS",
            "geo_x": 0,
            "geo_y": 0
        },
        {
            "ip": "111.111.111.111",
            "country": "",
            "region": "",
            "city": "",
            "isp": "日本东京市KDDI通信公司",
            "geo_x": 0,
            "geo_y": 0
        }
    ]
  2. 从纯真ip数据库获取ip信息

    接口

    POST /v1/db

    请求头

    1. Authorization = thisisaveryimportantkey(key可在config.go中配置)
    2. Content-Type = application/json

    Body

    {
        "ip":
            ["111.111.111.111", "8.8.8.8"]
    }

    返回

    [
        {
            "ip": "8.8.8.8",
            "country": "美国",
            "region": "",
            "city": "",
            "isp": "Google公共DNS",
            "geo_x": 0,
            "geo_y": 0
        },
        {
            "ip": "111.111.111.111",
            "country": "",
            "region": "",
            "city": "",
            "isp": "日本东京市KDDI通信公司",
            "geo_x": 0,
            "geo_y": 0
        }
    ]
  3. 从GeoLite2数据库获取ip信息

    接口

    POST /v1/db2

    请求头

    1. Authorization = thisisaveryimportantkey(key可在config.go中配置)
    2. Content-Type = application/json

    Body

    {
        "ip":
            ["111.111.111.111", "8.8.8.8"]
    }

    返回

    [
        {
            "ip": "8.8.8.8",
            "country": "美国",
            "region": "",
            "city": "",
            "isp": "Google公共DNS",
            "geo_x": 0,
            "geo_y": 0
        },
        {
            "ip": "111.111.111.111",
            "country": "",
            "region": "",
            "city": "",
            "isp": "日本东京市KDDI通信公司",
            "geo_x": 0,
            "geo_y": 0
        }
    ]
  4. 从ip2region数据库获取ip信息

    接口

    POST /v1/db3

    请求头

    1. Authorization = thisisaveryimportantkey(key可在config.go中配置)
    2. Content-Type = application/json

    Body

    {
        "ip":
            ["111.111.111.111", "8.8.8.8"]
    }

    返回

    [
        {
            "ip": "8.8.8.8",
            "country": "美国",
            "region": "",
            "city": "",
            "isp": "Google公共DNS",
            "geo_x": 0,
            "geo_y": 0
        },
        {
            "ip": "111.111.111.111",
            "country": "",
            "region": "",
            "city": "",
            "isp": "日本东京市KDDI通信公司",
            "geo_x": 0,
            "geo_y": 0
        }
    ]
  5. 整合以上四种方式获取ip信息,先异步查ip2region数据库(默认的主数据库),查不到的ip再查纯真, 再查GeoLite2数据库,最后通过api查询

    主数据库可在配置文件中配置(config.toml中的request_order配置)

    接口

    POST /v1/ip

    请求头

    1. Authorization = thisisaveryimportantkey(key可在config.go中配置)
    2. Content-Type = application/json

    Body

    {
        "ip":
            ["111.111.111.111", "8.8.8.8"]
    }

    返回

    [
        {
            "ip": "8.8.8.8",
            "country": "美国",
            "region": "",
            "city": "",
            "isp": "Google公共DNS",
            "geo_x": 0,
            "geo_y": 0
        },
        {
            "ip": "111.111.111.111",
            "country": "",
            "region": "",
            "city": "",
            "isp": "日本东京市KDDI通信公司",
            "geo_x": 0,
            "geo_y": 0
        }
    ]

项目结构

api\
   |api.go                      # api 方式查询 ip 信息主文件
   |baidu.go                    # 百度 ip API 服务解析
   |base.go                     # 通用接口
   |pconline.go                 # 太平洋 ip API 服务解析
   |sina.go                     # 新浪 ip API 服务解析
   |taobao.go                   # 淘宝 ip API 服务解析
config\
      |config.go                # 从 config.toml 读取配置以及其他配置
es\
  |es.go                        # elasticsearch 存储相关
geolite2\
        |geolite2.go            # db2 方式查询 ip 信息主文件
ip2region\
         |ip2region             # db3 方式查询 ip 信息主文件
         |lib                   # 解析 ip2region.db 的库文件
middleware\
          |auth.go              # 简单授权验证中间件
          |cors.go              # cors 跨域中间件
          |json_logger.go       # 日志服务中间件
          |sentry.go            # sentry 服务
qqwry\
     |qqwry.go                  # db 方式查询 ip 信息主文件
server\
     |server.go                 # /v1/ip 接口主文件
utils\
     |utils_test.go             # 工具包测试
     |utils.go                  # 工具包
config.toml                     # ipd 服务使用的配置文件
GeoLite2-City.mmdb              # geolite2 数据库二进制文件
Gopkg.lock                      # dep 包管理器 lock 文件
Gopkg.toml                      # dep 包管理器 toml 文件
ip2region.db                    # ip2region 数据库二进制文件
ipd.go                          # ipd 服务 main 包
qqwry.dat                       # 纯真 ip 数据库二进制文件
README.md                       # README

构建自己的ip信息数据库

ipd服务支持将查询过的ip信息添加到elasticsearch数据库,作后续其他的使用.默认启用elasticsearch存储

  1. 安装elasticsearch,建议安装最新版
  2. 修改config.toml中的elasticsearch段的url, 如果不想使用存储ip功能,将elasticsearch段注释即可

其他事项

  1. 程序默认使用sentry服务, 修改config.go中的dsn以使用自己的sentry,也可以注释掉config.toml中的sentry段来禁用sentry
  2. 更多设置请查看config.toml的备注说明

TODO

  • 添加es接口,直接从es查询ip数据
  • 增加精准查询接口(多种查询方式同时 goroutine,获取接口分析取最优)
  • 添加缓存机制
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].