Advertisement
Guest User

Python GeoIP Script

a guest
Jun 22nd, 2015
1,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #This is the Python script to query the MaxMind database!
  2. import pygeoip
  3. import socket
  4. gip = pygeoip.GeoIP('/root/pygeoip-0.1.3/GeoLiteCity.dat')
  5. print "Enter 1 to search for a URL or 2 to search for an IP address"
  6. userChoice = raw_input() #Get search type
  7. if userChoice == "1":
  8.     print ""
  9.     print "Enter URL"
  10.     URL = raw_input() #Get requested URL from user
  11.     ip = socket.gethostbyname(URL) #Retrieve URL's ip via socket
  12.     print "Requested IP: "+ ip
  13.     print ""
  14.     rec = gip.record_by_addr(ip) #Query database
  15.     for key,val in rec.items(): #Print results
  16.         print "%s: %s"%(key,val)
  17.     print ""
  18. elif userChoice == "2":
  19.     print ""
  20.     print "Enter IP"
  21.     ip = raw_input() #Get requested IP from user
  22.     rec = gip.record_by_addr(ip) #Query database
  23.     for key,val in rec.items(): #Print results
  24.         print "%s: %s"%(key,val)
  25.     print ""
  26. else:
  27.     print "That isn't an option" #In case of jackasses
  28.     print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement