You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

子域名查找器因‘label empty or too long’错误停止的原因排查

问题排查与修复方案

你遇到的label empty or too long错误,是因为字典文件里存在空行或者过长的子域名条目,导致生成的域名不符合DNS规则,而且代码没捕获这类异常,直接崩了。

具体原因:

  • 当字典里有空行时,line.strip()后得到空字符串,生成的test_url就是.youtube.com,这种域名在DNS解析时会触发"label empty"错误。
  • 如果字典里有超过63字符的子域名(DNS规定每个域名标签最长63字符),就会触发"label too long"错误。
  • 你的代码只捕获了ConnectionError和InvalidURL,但这类DNS解析错误属于底层的socket.gaierror,没被捕获,所以程序直接停止运行。

修复后的代码:

import requests
import socket

url = "youtube.com"

def request(test_url):
    try:
        return requests.get(f"http://{test_url}", timeout=2)
    except requests.exceptions.ConnectionError:
        pass
    except requests.exceptions.InvalidURL:
        print('INVALID URL:', test_url)
    except socket.gaierror as e:
        # 捕获DNS解析错误,比如label empty/too long
        print(f"DNS ERROR for {test_url}: {str(e)}")
    except requests.exceptions.RequestException as e:
        # 兜底捕获其他所有requests相关异常
        print(f"ERROR for {test_url}: {str(e)}")

with open("/home/kali/PycharmProjects/websitesub/subdomains-wodlist.txt", "r") as wordlist_file:
    for line in wordlist_file:
        word = line.strip()
        # 跳过空的子域名条目
        if not word:
            continue
        # 可选:验证子域名长度不超过63字符
        if len(word) > 63:
            print(f"SKIPPED too long subdomain: {word}")
            continue
        test_url = f"{word}.{url}"
        response = request(test_url)
        if response:
            print(f"Discovered SUBDOMAIN: {test_url}")

关键修复点:

  • 增加空条目过滤:if not word: continue,避免生成.youtube.com这种无效域名。
  • 捕获socket.gaierror处理DNS解析相关错误,程序不会直接崩溃。
  • 可选子域名长度检查,提前过滤过长的条目。
  • 用f-string替代字符串拼接,代码更清晰。
  • 兜底捕获RequestException,覆盖其他未预料到的requests异常。

内容的提问来源于stack exchange,提问作者Cezar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 20:05:33