跳到主要内容
uencoder

如何Encode Punycode Domains

转换 internationalized domain names (IDN) to Punycode ASCII representation for DNS resolution.

问题

你有 域 name 具有 non-ASCII characters (e.g., Bücher.com) 和 need 其 Punycode form 为 DNS lookups.

前置条件

  • Understanding 的 DNS
  • 熟悉Unicode

步骤

  1. 1. Split the domain into labels

    Separate the domain name at each dot. Punycode is applied per-label, not to the whole domain. The TLD and each subdomain label are processed independently.

    输入
    Bücher.com
    输出
    labels: ['Bücher', 'com']
  2. 2. Encode each non-ASCII label to Punycode

    For each label containing non-ASCII characters, prefix the Punycode output with xn-- and append the encoded form. ASCII-only labels like 'com' remain unchanged. The encoding maps Unicode code points to a compact ASCII representation.

    输入
    Bücher
    输出
    xn--Bcher-kva
  3. 3. Reassemble and verify

    Join the encoded labels with dots. Use the result for DNS resolution. Most browsers and DNS libraries perform this conversion automatically, but APIs and logs often show the Punycode form.

    输入
    xn--Bcher-kva.com
    输出
    resolves to the same server as Bücher.com

预期结果

ASCII-仅域 name (ACE form) 该 DNS resolvers 能够查询, equivalent 到原始 IDN.

常见错误

Encoding the entire domain as one label
Split on dots first. Only labels with non-ASCII characters get the xn-- prefix.
Case is lost in conversion
Punycode preserves the case of the first character. Use a standards-compliant encoder to handle case correctly.

排障指引

  • If DNS lookup fails, verify the xn-- prefix is present and lowercase.
  • Some older resolvers do not support IDN. Use the Punycode form directly in those cases.

安全限制

  • Punycode enables homograph attacks (e.g., аpple.com using Cyrillic а). Always display the Unicode form to users and warn about mixed-script domains.

相关工具

相关词条

参考链接