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