-2

I am trying to find the Country of a database of IPs in Python. As a test I tried to find the location of one IP using pygeoip. However my code is not producing any output. The print statement is not giving me any output. It's my first time using this package and I am not sure how variable is stored.

I am using Pycharm to run the code.

import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat')
Country = gi.country_code_by_name('64.233.161.99')
print(Country)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Indu
  • 1
  • 2

1 Answers1

0

I think it's because you're using country_code_by_name instead of country_code_by_addr. Either that or GeoIP.dat doesn't have data for it. Try using this link to update yours.

The code you should do instead: Country = gi.country_code_by_addr('64.233.161.99')

Axiumin_
  • 2,107
  • 2
  • 15
  • 24
  • Hi Thanks for the reply, but the link you showed does not have a .dat file.They are mmd and csv files. Do you happen to know a link for .dat file? – Indu Jan 06 '19 at 04:43