import urllib.request, json, sys

for port in [9222, 9223]:
    try:
        data = json.loads(urllib.request.urlopen(f'http://localhost:{port}/json', timeout=2).read())
        print(f"端口 {port}: {len(data)} 个页面")
        for p in data:
            if p.get('type') == 'page':
                print(f"  {p['url'][:80]}")
    except Exception as e:
        print(f"端口 {port}: 未占用 ({e})")
