Skip to content

Instantly share code, notes, and snippets.

@hellais
Last active May 27, 2016 12:27
Show Gist options
  • Save hellais/6833969f10067ac7748c to your computer and use it in GitHub Desktop.
Save hellais/6833969f10067ac7748c to your computer and use it in GitHub Desktop.
IP to ASN
#!/usr/bin/env python
# To get GeoIPASNum.dat:
# wget https://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz && gunzip GeoIPASNum.dat.gz
import sys
import pygeoip
if len(sys.argv) < 2:
print "Usage: path/to/GeoIPASNum.dat [IPs ... ...]"
ips = sys.argv[2:]
gi = pygeoip.GeoIP(sys.argv[1])
for ip in ips:
print gi.asn_by_name(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment