ip2location

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package ip2location implements downloading and parsing of ip2location databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Update

func Update(outputPath string, apiKey string) error

Update will fetch a new geoip database from maxmind and install it, uncompressed, into the configured geodb_path defined in the configuration file.

Types

type ASNRecord

type ASNRecord struct {
	IPFrom *net.IP
	IPTo   *net.IP
	CIDR   *net.IPNet
	ASNum  uint64
	ASName string
}

ASNRecord ip_from INT (10)† / DECIMAL (39,0)†† First IP address show netblock. ip_to INT (10)† / DECIMAL (39,0)†† Last IP address show netblock. cidr VARCHAR(43) IP address range in CIDR. asn INT(10) Autonomous system number (ASN). as VARCHAR(256) Autonomous system (AS) name.

type ASNRecords added in v0.1.8

type ASNRecords []ASNRecord

func (ASNRecords) Hosts added in v0.1.8

func (r ASNRecords) Hosts() uint32

type BlockListData

type BlockListData struct {
	ASN4       []ASNRecord
	ASN6       []ASNRecord
	Locations4 []LocationRecord
	Locations6 []LocationRecord
	Proxies    []ProxyRecord
}

func Read

func Read(root string) (*BlockListData, error)

type LatLong

type LatLong struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

func (*LatLong) Scan

func (ll *LatLong) Scan(v interface{}) error

Scan implements the sql.Scanner interface for conversion to our custom type

func (LatLong) String

func (ll LatLong) String() string

String returns a comma separated lat long pair string

func (*LatLong) Value

func (ll *LatLong) Value() (driver.Value, error)

Value implements the driver.Valuer interface for our custom type

type Location

type Location struct {
	ISOCode string
	LatLong LatLong
	// Autonomous system number (ASN)
	ASN uint64
	// Autonomous system (AS) name
	AS string
}

Location provides a container and some helper functions for location data

type LocationRecord

type LocationRecord struct {
	IPFrom      *net.IP
	IPTo        *net.IP
	CountryCode string
	CountryName string
	RegionName  string
	CityName    string
	LatLong     LatLong
}

LocationRecord "16781312","16785407","JP","Japan","Tokyo","Tokyo","35.689506","139.691700" ip_from INT (10)† / DECIMAL (39,0)†† First IP address show netblock. ip_to INT (10)† / DECIMAL (39,0)†† Last IP address show netblock. country_code CHAR(2) Two-character country code based on ISO 3166. country_name VARCHAR(64) Country name based on ISO 3166. region_name VARCHAR(128) Region or state name. city_name VARCHAR(128) City name. latitude DOUBLE City latitude. Default to capital city latitude if city is unknown. longitude DOUBLE City longitude. Default to capital city longitude if city is unknown.

type ProxyRecord

type ProxyRecord struct {
	IPFrom      *net.IP
	IPTo        *net.IP
	ProxyType   ProxyType
	CountryCode string
	CountryName string
	RegionName  string
	CityName    string
	ISP         string
	Domain      string
	UsageType   UsageType
	ASN         int64
	AS          string
	LastSeen    time.Time
	Threat      ThreatType
}

ProxyRecord ip_from INT (10)† / DECIMAL (39,0)†† First IP address show netblock. ip_to INT (10)† / DECIMAL (39,0)†† Last IP address show netblock. proxy_type VARCHAR(3) Type of proxy country_code CHAR(2) Two-character country code based on ISO 3166. country_name VARCHAR(64) Country name based on ISO 3166. region_name VARCHAR(128) Region or state name. city_name VARCHAR(128) City name. isp VARCHAR(256) Internet Service Provider or company's name. domain VARCHAR(128) Internet domain name associated with IP address range. usage_type VARCHAR(11) Usage type classification of ISP or company.

(COM) Commercial
(ORG) Organization
(GOV) Government
(MIL) Military
(EDU) University/College/School
(LIB) Library
(CDN) Content Delivery Network
(ISP) Fixed Line ISP
(MOB) Mobile ISP
(DCH) Data Center/Web Hosting/Transit
(SES) Search Engine Spider
(RSV) Reserved

asn INT(10) Autonomous system number (ASN). as VARCHAR(256) Autonomous system (AS) name. last_seen INT(10) Proxy last seen in days. threat VARCHAR(128) Security threat reported.

type ProxyType added in v0.1.8

type ProxyType string
const PUB ProxyType = "PUB"

type ThreatType added in v0.1.8

type ThreatType string
const (
	ThreatUnknown           ThreatType = "-"
	ThreatSpam              ThreatType = "SPAM"
	ThreatBotnet            ThreatType = "BOTNET"
	ThreatScanner           ThreatType = "SCANNER"
	ThreatSpamBotnet        ThreatType = "SPAM/BOTNET"
	ThreatSpamScanner       ThreatType = "SPAM/SCANNER"
	ThreatSpamScannerBotnet ThreatType = "SPAM/SCANNER/BOTNET"
)

type UsageType added in v0.1.8

type UsageType string
const (
	UsageContentDeliveryNetwork UsageType = "CDN"
	UsageISPFixedMobile         UsageType = "ISP/MOB"
	UsageCommercial             UsageType = "COM"
	UsageISPMobile              UsageType = "MOB"
	UsageLibrary                UsageType = "LIB"
	UsageDataCenter             UsageType = "DCH"
	UsageMilitary               UsageType = "MIL"
	UsageGovernment             UsageType = "GOV"
	UsageISPFixed               UsageType = "ISP"
	UsageOrganization           UsageType = "ORG"
	UsageEducation              UsageType = "EDU"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL