Advertisement
rfmonk

dpkt_retGeo.py

Nov 30th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import dpkt, socket, pygeoip, optparse
  4. gi = pygeoip.GeoIP("/opt/GeoIP/Geo.dat")
  5. def retGeoStr(ip):
  6.     try:
  7.         rec = gi.record_by_name(ip)
  8.         city = rec['city']
  9.         country = rec['country_code3']
  10.         if (city!=''):
  11.             geoLoc= city+", "+country
  12.         else:
  13.             geoLoc=country
  14.         return geoLoc
  15.     except:
  16.         return "Unregistered"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement