import re,sys
blocks=[];cur=None
for raw in open(sys.argv[1],encoding='utf-8',errors='replace'):
    m=re.match(r'^([A-Za-z][A-Za-z /]*?):\s{2,}(.*)$',raw.rstrip('\r\n'))
    if not m: continue
    k,v=m.group(1).strip(),m.group(2).strip()
    if k=='Rule Name': cur={'Rule Name':v};blocks.append(cur)
    elif cur is not None: cur[k]=v
g=lambda b,k: b.get(k,'')
en=[b for b in blocks if g(b,'Enabled')=='Yes' and g(b,'Action')=='Allow']
assert [b for b in en if '5470' in g(b,'LocalPort')] and [b for b in en if 'spt.exe' in g(b,'Program').lower()], "CONTROLS FAILED"
base=[b for b in en if g(b,'Program') in ('Any','') and g(b,'LocalPort') in ('Any','')
      and g(b,'Protocol') in ('TCP','Any') and 'Private' in g(b,'Profiles')]
print("my old predicate (no LocalIP):",len(base))
anyip=[b for b in base if g(b,'LocalIP') in ('Any','')]
pinned=[b for b in base if g(b,'LocalIP') not in ('Any','')]
print("  of which LocalIP=Any (true LAN-relevant blanket candidates):",len(anyip))
print("  of which LocalIP pinned to a specific address (NOT LAN blankets):",len(pinned))
for b in pinned: print("     PINNED:",g(b,'Rule Name'),"| LocalIP",g(b,'LocalIP'),"| proto",g(b,'Protocol'))
