Skip to content

Instantly share code, notes, and snippets.

@timss
Created May 2, 2013 15:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save timss/5503221 to your computer and use it in GitHub Desktop.
Save timss/5503221 to your computer and use it in GitHub Desktop.
Script to get ISP from host (ip/domain) using ip-adress.com.
#!/usr/bin/env python
import html2text
import re
import sys
import urllib2
def get_ip(host):
trac = "http://www.ip-adress.com/ip_tracer/"
pat = "ISP of this IP \[\?\]:\n\n([a-zA-Z ]+)"
hdr = {'User-Agent': 'Mozilla/5.0'} # ip-adress.com only accepts popular agents
req = urllib2.Request(trac + host, headers=hdr)
page = urllib2.urlopen(req).read()
h = html2text.HTML2Text()
h.ignore_links = True
text = h.handle(page)
try:
print "ISP for %s:\n" % host, re.search(pat, text).group(1)
except:
print "Could not find ISP for", host
def main():
if len(sys.argv) < 2:
print('Usage: ' + sys.argv[0] + ' host.')
sys.exit(1)
get_ip(sys.argv[1])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment