8 with open(sys.argv[1]) as fin, open(sys.argv[2], "w") as fou:
12 lo_matcher = re.compile("\A(?P<left>.+)\s+-i\s+lo\s+-j\s+ACCEPT")
13 # what comes out of iptables-save has short-options syntax
14 ip_matcher = re.compile(".*-(s|d) %s" % ip)
15 for line in fin.readlines():
16 attempt = lo_matcher.match(line)
20 fou.write("%s -s %s -j ACCEPT\n" % (attempt.group('left'), ip))
21 fou.write("%s -d %s -j ACCEPT\n" % (attempt.group('left'), ip))
24 attempt = ip_matcher.match(line)
25 # do not rewrite old lines for this ip
34 if __name__ == '__main__':