From 8a982a849b06902af7f88215781b14350cb0240d Mon Sep 17 00:00:00 2001 From: Minoplhy Date: Thu, 12 Aug 2021 17:46:03 +0700 Subject: [PATCH] Regex attempt 7 --- to-rpz/host_rpz_argv.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/to-rpz/host_rpz_argv.py b/to-rpz/host_rpz_argv.py index 9159cc7..6f6b1fb 100644 --- a/to-rpz/host_rpz_argv.py +++ b/to-rpz/host_rpz_argv.py @@ -18,6 +18,15 @@ with open(infile, 'w') as f1: f1.writelines(["%s\n" % item for item in file]) f.close() +remove_words = ['localhost','localhost.localdomain','local','broadcasthost','loopback','ip6-localnet','ip6-mcastprefix','ip6-allnodes','ip6-allrouters','ip6-allhosts','ip6-loopback'] + +with open(infile, 'r') as f: + lines = f.read().splitlines() +with open(outfile, 'w') as f: + for line in lines: + if not line.endswith((tuple(remove_words))): + f.write('\n'.join([line + '\n'])) + with open(infile) as f: file = f.read().split('\n') for i in range(len(file)): @@ -43,15 +52,6 @@ with open(infile, 'w') as f: # load file in write mode f.write('\n'.join([line + '\n'])) f.close() -remove_words = ['localhost','localhost.localdomain','local','broadcasthost','loopback','ip6-localnet','ip6-mcastprefix','ip6-allnodes','ip6-allrouters','ip6-allhosts','ip6-loopback'] - -with open(infile, 'r') as f: - lines = f.read().splitlines() -with open(outfile, 'w') as f: - for line in lines: - if not line.endswith((tuple(remove_words))): - f.write('\n'.join([line + '\n'])) - with open(infile) as f: file = f.read().split('\n') for i in range(len(file)):