Skip to content
This repository has been archived by the owner on Apr 6, 2018. It is now read-only.

Commit

Permalink
- Fixed Python 2.7/3.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnim committed Apr 17, 2017
1 parent 9a767fd commit a24dda0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions netchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@

### The 'netaddr' module can be downloaded through PyPi (pip install ...) or installed
### through your package manager of choice.
import netaddr,sys,re,csv,optparse,urllib2,zipfile,os
import netaddr,sys,re,csv,optparse,zipfile,os

### Python 2/3 compatibility
try:
import urllib2 as urllib
except ImportError:
import urllib

def UpdateGeoIP():
"""
Download the GeoLite IP databases from MaxMind and unpack them into the current working directory.
This will overwrite any existing file(s) with the same name.
"""
try:
response=urllib2.urlopen(GeoIPURL+GeoIPURLzip)
except urllib2.URLError as e:
response=urllib.urlopen(GeoIPURL+GeoIPURLzip)
except urllib.URLError as e:
print("E) An error occurred downloading "+GeoIPURL+GeoIPURLzip+": "+e.reason)
try:
with open(GeoIPURLzip,'wb') as f:
Expand All @@ -38,8 +44,8 @@ def UpdateGeoIP():
except:
print("E) An error occured unzipping "+GeoIPURLzip)
try:
response=urllib2.urlopen(GeoIPURL+GeoIPv6URLzip)
except urllib2.URLError as e:
response=urllib.urlopen(GeoIPURL+GeoIPv6URLzip)
except urllib.URLError as e:
print("E) An error occurred downloading "+GeoIPURL+GeoIPv6URLzip+": "+e.reason)
try:
with open(GeoIPv6URLzip,'wb') as f:
Expand Down

0 comments on commit a24dda0

Please sign in to comment.