forked from wraith-wireless/PyRIC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code compatible with python2 and python3
- Loading branch information
1 parent
ac5eda8
commit 97f0095
Showing
10 changed files
with
85 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,17 @@ | |
__email__ = '[email protected]' | ||
__status__ = 'Production' | ||
|
||
import urllib2,os,sys,datetime,time | ||
|
||
import os,sys,datetime,time | ||
try: | ||
from urllib2 import Request | ||
from urllib2 import urlopen | ||
from urllib2 import URLError | ||
except: | ||
from urllib.request import Request | ||
from urllib.request import urlopen | ||
from urllib.error import URLError | ||
|
||
#import argparse as ap | ||
import pyric | ||
|
||
|
@@ -75,22 +85,22 @@ def fetch(opath=None,verbose=False): | |
# determine if data path is legit | ||
if opath is None: opath = OUIPATH | ||
if not os.path.isdir(os.path.dirname(opath)): | ||
print "Path to data is incorrect {0}".format(opath) | ||
print("Path to data is incorrect {0}".format(opath)) | ||
sys.exit(1) | ||
|
||
# fetch oui file from ieee | ||
fout = None | ||
|
||
# set up url request | ||
req = urllib2.Request(OUIURL) | ||
req = Request(OUIURL) | ||
req.add_header('User-Agent',"PyRIC +https://github.com/wraith-wireless/PyRIC/") | ||
try: | ||
# retrieve the oui file and parse out generated date | ||
if verbose: print 'Fetching ', OUIURL | ||
res = urllib2.urlopen(req) | ||
if verbose: print "Parsing OUI file" | ||
if verbose: print('Fetching ', OUIURL) | ||
res = urlopen(req) | ||
if verbose: print("Parsing OUI file") | ||
|
||
if verbose: print "Opening data file {0} for writing".format(opath) | ||
if verbose: print("Opening data file {0} for writing".format(opath)) | ||
fout = open(opath,'w') | ||
gen = datetime.datetime.utcnow().isoformat() # use current time as the first line | ||
fout.write(gen+'\n') | ||
|
@@ -110,14 +120,14 @@ def fetch(opath=None,verbose=False): | |
# write to file & update count | ||
fout.write('{0}\t{1}\n'.format(oui,manuf)) | ||
cnt += 1 | ||
if verbose: print "{0}:\t{1}\t{2}".format(cnt,oui,manuf) | ||
print "Wrote {0} OUIs in {1:.3} secs".format(cnt,time.time()-t) | ||
except urllib2.URLError as e: | ||
print "Error fetching oui file: {0}".format(e) | ||
if verbose: print("{0}:\t{1}\t{2}".format(cnt,oui,manuf)) | ||
print("Wrote {0} OUIs in {1:.3} secs".format(cnt,time.time()-t)) | ||
except URLError as e: | ||
print("Error fetching oui file: {0}".format(e)) | ||
except IOError as e: | ||
print "Error opening output file {0}".format(e) | ||
print("Error opening output file {0}".format(e)) | ||
except Exception as e: | ||
print "Error parsing oui file: {0}".format(e) | ||
print("Error parsing oui file: {0}".format(e)) | ||
finally: | ||
if fout: fout.close() | ||
|
||
|
Oops, something went wrong.