Git Product home page Git Product logo

datx-go's Introduction

datx-go

IPIP.net官方支持datx格式的解析代码

安装 Installation

go get github.com/ipipdotnet/datx-go

示例 Usage


package main

import "github.com/ipipdotnet/datx-go"
import "fmt"

func main(){

    city, err := datx.NewCity("/path/to/17monipdb.datx") // For City Level IP Database
    if err == nil {
        fmt.Println(city.Find("8.8.8.8"))
        fmt.Println(city.Find("128.8.8.8"))
        fmt.Println(city.Find("255.255.255.255"))
        loc, err := city.FindLocation("27.190.252.103")
        if err == nil {
            fmt.Println(string(loc.ToJSON()))
            // Output:
            /*
            {
                "Country": "China",
                "Province": "Hebei",
                "City": "Tangshan",
                "Organization": "",
                "ISP": "ChinaTelecom",
                "Latitude": "39.635113",
                "Longitude": "118.175393",
                "TimeZone": "Asia/Shanghai",
                "TimeZone2": "UTC+8",
                "CityCode": "130200",
                "PhonePrefix": "86",
                "CountryCode": "CN",
                "ContinentCode": "AP",
                "IDC": "",
                "BaseStation": "",
                "Anycast": false
            }
            */
        }
    }
    dis, err := datx.NewDistrict("/path/to/quxian.datx") // Only China District IP Database
    if err == nil {
        fmt.Println(dis.Find("1.12.46.0"))
        fmt.Println(dis.Find("223.255.127.0"))
    }
    bst, err := datx.NewBaseStation("/path/to/station_ip.datx") // Only China Base Station IP Database
    if err == nil {
        fmt.Println(bst.Find("1.30.6.0"))
        fmt.Println(bst.Find("223.221.121.0"))
        fmt.Println(bst.Find("223.221.121.255"))
    }    
}

datx-go's People

Contributors

ilsanbao avatar ipipdotnet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.