Socket
Socket
Sign inDemoInstall

gitlab.torproject.org/tpo/anti-censorship/geoip

Package Overview
Dependencies
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gitlab.torproject.org/tpo/anti-censorship/geoip

This code is for loading database data that maps ip addresses to countries for collecting and presenting statistics on snowflake use that might alert us to censorship events. The functions here are heavily based off of how tor maintains and searches their geoip database The tables used for geoip data must be structured as follows: Recognized line format for IPv4 is: Note that the IPv4 line format is not currently supported. Recognized line format for IPv6 is: It also recognizes, and skips over, blank lines and lines that start with '#' (comments).


Version published

Readme

Source

geoip go library

Get the country code for an IP address using the tor's geoip database.

example

Needs the path of the geoip database in the initialization. For example in debian it is provided by tor-geoipdb and the path is /usr/share/tor/geoip and /usr/share/tor/geoip6.

geo, err := geoip.New("/usr/share/tor/geoip", "/usr/share/tor/geoip6")
if err != nil {
	// Handle error
}

ip := net.ParseIP("12.13.14.15")
country, ok := geo.GetCountryByAddr(ip)
if !ok {
	fmt.Println("Not found any country for the IP")
} else {
	fmt.Println("The ip corresponds to the country:", country)
}

FAQs

Last updated on 28 Sep 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc