8000 GitHub - 373518155/ip2asn: lookup AS number for IPv4 address
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
forked from zhangyoufu/ip2asn

lookup AS number for IPv4 address

Notifications You must be signed in to change notification settings

373518155/ip2asn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

introduction

A golang package to lookup AS number for IPv4 address. This package does not come with a database, you have to download one yourself.

supported data source

  1. IP2Location LITE IP-ASN Database (recommended)
  2. MaxMind GeoLite2 ASN CSV Database

example

package main

import (
    "bufio"
    "fmt"
    "os"

    "github.com/zhangyoufu/ip2asn"
)

func main() {
    fmt.Println("loading...")
    ds, err := ip2asn.IP2LocationDataSource.Load("IP2LOCATION-LITE-ASN.CSV.ZIP", nil)
    if err != nil {
        panic(err)
    }
    fmt.Println("loaded")

    fmt.Println("input any IPv4 address and press Enter to query")
    s := bufio.NewScanner(os.Stdin)
    for s.Scan() {
        ipAddr := s.Text()
        asNum := ds.GetAsNum(ipAddr)
        if asNum == 0 {
            fmt.Println("not found")
        } else {
            fmt.Printf("AS%d %s\n", asNum, ds.GetAsName(asNum))
        }
    }
}

About

lookup AS number for IPv4 address

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%
0