使用 DNSJava 解析 Verisign COM 区域文件

Parsing Verisign COM Zone File with DNSJava

我正在尝试使用 DNSJava 中的 Master 解析器读取 Verisign COM 主区域文件。

这是一个示例输入:

; The use of the Data contained in Verisign Inc.'s aggregated
; .com, and .net top-level domain zone files (including the checksum
; files) is subject to the restrictions described in the access Agreement
; with Verisign Inc.

$ORIGIN COM.
$TTL 900
@ IN    SOA     a.gtld-servers.net. nstld.verisign-grs.com. (
                  1539446539 ;serial
                  1800 ;refresh every 30 min
                  900 ;retry every 15 min
                  604800 ;expire after a week
                  86400 ;minimum of a day
                  )
$TTL 172800
 NS A.GTLD-SERVERS.NET.
 NS G.GTLD-SERVERS.NET.
 NS H.GTLD-SERVERS.NET.
 NS C.GTLD-SERVERS.NET.
 NS I.GTLD-SERVERS.NET.
 NS B.GTLD-SERVERS.NET.
 NS D.GTLD-SERVERS.NET.
 NS L.GTLD-SERVERS.NET.
 NS F.GTLD-SERVERS.NET.
 NS J.GTLD-SERVERS.NET.
 NS K.GTLD-SERVERS.NET.
 NS E.GTLD-SERVERS.NET.
 NS M.GTLD-SERVERS.NET.
COM. 86400 DNSKEY 257 3 8 AQPDzldNmMvZFX4NcNJ0uEnKDg7tmv/F3MyQR0lpBmVcNcsIszxNFxsBfKNW9JYCYqpik8366LE7VbIcNRzfp2h9OO8HRl+H+E08zauK8k7evWEmu/6od+2boggPoiEfGNyvNPaSI7FOIroDsnw/taggzHRX1Z7SOiOiPWPNIwSUyWOZ79VmcQ1GLkC6NlYvG3HwYmynQv6oFwGv/KELSw7ZSdrbTQ0HXvZbqMUI7BaMskmvgm1G7oKZ1YiF7O9ioVNc0+7ASbqmZN7Z98EGU/Qh2K/BgUe8Hs0XVcdPKrtyYnoQHd2ynKPcMMlTEih2/2HDHjRPJ2aywIpKNnv4oPo/
COM. 86400 DNSKEY 256 3 8 AQPepKpvbFtHVsAVm8kq+659WxFYXre5ngCIL53NuAMPybKPNEqgzF4+7GJExZB9LIDTH3ZK4QYAm7R14wEf9qGAjOpyIGF2jXqMkQ2G272hbEkFw6q5fawQByh3K7rXY8SAf2abpiXXh+Ms6LsvMarOpc7SwEt7Dbp1nvqgCA9jHw==
COM. 86400 DNSKEY 256 3 8 AQPeabgR6Fgrk5FSLilDYUedwsHA0HH22e8+Zp/uvp4aj1dVDAy5C9bkRA+xot3sG1KaT5hvgoE7eNV93F7pBW9rvVE3A/BNvJbLXxKhkAJV5KMFC10NRcdb+xF+sM4XTMPESPrYwTLUEpSFntMIVLAtUzLaBo6YpTVR20osgGgc3Q==
COM. 86400 NSEC3PARAM 1 0 0 -
COM. 86400 RRSIG NSEC3PARAM 8 1 86400 20181019044209 20181012033209 46475 COM. l0FoGsy2lG+9tlm2AA2wPNDAJV2PwhTVjUbSqGMcJqWc8ZTXlnUkaWnje4ws7KmAJIyQe3dMQ/RnZoF0CQluNilPWWVNm/Zz01r+M96V288H36UiiP0aPX9OcPaSCxRumuZmeiHNOWmMm+fbwNtPSJa3IkxKXMM1dT0qJ24n5v8=
COM. RRSIG NS 8 1 172800 20181019044209 20181012033209 46475 COM. LPV6Rjixhji/PQonHzKlnPxen/R/mZugUaj+fSpSQzQ7o4YLzZZ0k0J8linUu+RvdeI3p7+mdnUp5OergS7LAIsE2cQcvTpggJsi8aZk6r7QeqlvcYIEZfQ9vNpUVmZ/649SXvQppSq/RBbM4e0a1QQlUzXKiEUU53VDq2CUcnk=
COM. 900 RRSIG SOA 8 1 900 20181020160219 20181013145219 46475 COM. dbMGDD6f+2EEZMigc6FbzUj8Ou05s5iUmg7fhrKRu4vRUhZoG1MNqJ8Jy1LtyUTRswtp2xhY+n7g7zBxNBlpgOnseovEjmuEUz34P6h40jkSKvk75iSVKc9tFLciZi0svVQFL7B3eVKRR/zGsY6z4qX9cPWJHh5wwLYO3JgsQls=
COM. 86400 RRSIG DNSKEY 8 1 86400 20181019182533 20181004182033 30909 COM. vnSL1FfsX1/3qQw8ee20JqOAa9UNEvNjgCEmMu6HHfgQTKFy15DLMOA5VIWja6fbtASkc8YHJ5PWowWpWGiX9gE0g5i3TlMpiu6H3MQBjMgJWhtivzruEo4k2OknKRpfV18+rVf0MB55OAbqGS/J838PUFiYs7Rt7W7gYdFNRhWzS6VbdHElub0ySy4ZJTAt0muG7MphffC/Fgh9drgL0mpjfD2HynBbCKtgXOXJ6fHT6erkN2hMxu0AkJVwReNsQagOddtsK7RPPo1hfe5oZYBigVWtE/rvj6zHrRNKbyIcz+4fXpGmgayB2TACWc8vvRqcB3+VDaGxzIV4hGBo7Q==
KITCHENEROKTOBERFEST NS NS1.UNIREGISTRYMARKET.LINK.
KITCHENEROKTOBERFEST NS NS2.UNIREGISTRYMARKET.LINK.
KITCHENFLOORTILE NS NS1.UNIREGISTRYMARKET.LINK.
KITCHENFLOORTILE NS NS2.UNIREGISTRYMARKET.LINK.
KITCHENTABLESET NS NS1.UNIREGISTRYMARKET.LINK.
KITCHENTABLESET NS NS2.UNIREGISTRYMARKET.LINK.
KITEPICTURES NS NS1.UNIREGISTRYMARKET.LINK.
KITEPICTURES NS NS2.UNIREGISTRYMARKET.LINK.

我能够解析来自 ICANN 的 CZDS 程序的其他区域文件,但 Verisign 的文件抛出此异常:

Caused by: org.xbill.DNS.Tokenizer$TokenizerException: :2: expected a string at org.xbill.DNS.Tokenizer.exception(Tokenizer.java:710) at org.xbill.DNS.Tokenizer.getString(Tokenizer.java:374) at org.xbill.DNS.Master.parseTTLClassAndType(Master.java:134) at org.xbill.DNS.Master._nextRecord(Master.java:364) at org.xbill.DNS.Master.nextRecord(Master.java:388) ... 28 more

我可以使用此代码和 dnsjava 2.1.8 解析您的文件片段:

import org.xbill.DNS.Master;
import org.xbill.DNS.Name;

public class parse {
    public static void main(String[] args) throws Exception {
        var master = new Master(args[0], Name.root, 86400);
        while (true) {
            var rr = master.nextRecord();
            if (rr == null)
                break;
            System.out.println(rr);
        }
    }
}