Convert scripts to python3
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# !/usr/bin/env python
|
||||
# !/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import binascii
|
||||
import os
|
||||
import ConfigParser
|
||||
import configparser
|
||||
from pybloom import BloomFilter
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ def main():
|
||||
configfiles.append(args.config)
|
||||
|
||||
#build config
|
||||
conf = ConfigParser.ConfigParser()
|
||||
conf = configparser.ConfigParser()
|
||||
conf.read(configfiles)
|
||||
#add commandline options
|
||||
# conf=config["config"]
|
||||
@@ -74,25 +74,25 @@ def main():
|
||||
hashfile_column=conf.getint("config",'hashfile_column')
|
||||
hashfile_type=conf.get("config",'hashfile_type')
|
||||
|
||||
print "[BUILDING] Using error-rate: {}".format(error_rate)
|
||||
print("[BUILDING] Using error-rate: {}".format(error_rate))
|
||||
if os.path.isfile(nsrl_path):
|
||||
print "[BUILDING] Reading in NSRL Database"
|
||||
print("[BUILDING] Reading in NSRL Database")
|
||||
if not conf.has_option("config","hash_count"):
|
||||
with open(nsrl_path) as f_line:
|
||||
# Strip off header
|
||||
_ = f_line.readline()
|
||||
print "[BUILDING] Calculating number of entries in Inputfile..."
|
||||
print("[BUILDING] Calculating number of entries in Inputfile...")
|
||||
num_lines = sum(bl.count("\n") for bl in blocks(f_line))
|
||||
conf.set("config",'hash_count',str(num_lines))
|
||||
else:
|
||||
num_lines=conf.getint("config","hash_count")
|
||||
print "[BUILDING] There are {} {}s in the Database".format(num_lines,hashfile_type)
|
||||
print("[BUILDING] There are {} {}s in the Database".format(num_lines,hashfile_type))
|
||||
with open(nsrl_path) as f_nsrl:
|
||||
# Strip off header
|
||||
_ = f_nsrl.readline()
|
||||
print "[BUILDING] Creating bloomfilter"
|
||||
print("[BUILDING] Creating bloomfilter")
|
||||
bf = BloomFilter(num_lines, error_rate)
|
||||
print "[BUILDING] Inserting {} into bloomfilter".format(hashfile_type)
|
||||
print("[BUILDING] Inserting {} into bloomfilter".format(hashfile_type))
|
||||
# sha1 hash is in column 0
|
||||
for line in f_nsrl:
|
||||
hashline = line.split(hashfile_delimiter)[hashfile_column].strip('"')
|
||||
@@ -101,11 +101,11 @@ def main():
|
||||
hash = binascii.unhexlify(hashline)
|
||||
bf.add(hash)
|
||||
except Exception as e:
|
||||
print "[ERROR] %s" % e
|
||||
print "[BUILDING] NSRL bloomfilter contains {} items.".format(len(bf))
|
||||
print("[ERROR] %s" % e)
|
||||
print("[BUILDING] NSRL bloomfilter contains {} items.".format(len(bf)))
|
||||
with open('nsrl.bloom', 'wb') as nb:
|
||||
bf.tofile(nb)
|
||||
print "[BUILDING] Complete"
|
||||
print("[BUILDING] Complete")
|
||||
else:
|
||||
print("[ERROR] No such file or directory: %s", nsrl_path)
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import binascii
|
||||
import ConfigParser
|
||||
import configparser
|
||||
import sys
|
||||
|
||||
from pybloom import BloomFilter
|
||||
|
||||
def main():
|
||||
default_config_file='/nsrl/nsrl.conf'
|
||||
config = ConfigParser.ConfigParser()
|
||||
config = configparser.ConfigParser()
|
||||
config.read(default_config_file)
|
||||
#add commandline options
|
||||
hash_type=config.get('config','hashfile_type')
|
||||
@@ -54,11 +54,11 @@ def main():
|
||||
output = "{}".format(hash_hex)
|
||||
else:
|
||||
output = "{}:{}".format("+"if hash_is_a_match else "-",hash_hex)
|
||||
print output
|
||||
print(output)
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
print "Error: %s" % e
|
||||
print("Error: %s" % e)
|
||||
|
||||
Reference in New Issue
Block a user