更新dns.php版本,解决googleDNS、CloudFlareDNS等dns递归时携带DNSSEC后无法解析的问题

This commit is contained in:
Enoch 2024-01-29 17:20:41 +08:00
parent bfa4742524
commit e6c19f90a1
2 changed files with 58 additions and 1 deletions

View File

@ -1,6 +1,7 @@
# Webman DNS # Webman DNS
Webman的DNS服务器插件可以实现Webman启动时运行一个DNS服务器 Webman的DNS服务器插件可以实现Webman启动时运行一个DNS服务器
请不要用于生产环境。
> 注意默认为udp53端口需要ROOT权限 > 注意默认为udp53端口需要ROOT权限
@ -26,6 +27,8 @@ Webman的DNS服务器插件可以实现Webman启动时运行一个DNS服务
## 安装 ## 安装
在确保已经安装webman后执行
```shell ```shell
composer require laysense/dns composer require laysense/dns
``` ```
@ -96,7 +99,8 @@ class DnsController
} }
``` ```
具体的使用方式请参照 [Workerman-DNS](https://www.workerman.net/a/1439) ([Github](https://github.com/ywnsya/workerman-dns)) 下的start.php 具体的使用方式请参照 [Workerman-DNS](https://git.laysense.com/enoch/Workerman-DNS) ([Github](https://github.com/ywnsya/workerman-dns)) 下的start.php
## 赞助(我不要脸) ## 赞助(我不要脸)

View File

@ -369,8 +369,11 @@ class Dns
*/ */
public static function decode($buffer) public static function decode($buffer)
{ {
/**
$data=bin2hex($buffer); $data=bin2hex($buffer);
echo $data;
$id=substr($data,0,4); $id=substr($data,0,4);
$flag=substr($data,5,4);
$type=substr($data,-8,4); $type=substr($data,-8,4);
switch($type){ switch($type){
case '0001': case '0001':
@ -410,8 +413,58 @@ class Dns
} }
$realname=substr($realname,1,-1); $realname=substr($realname,1,-1);
$query=substr($data,24); $query=substr($data,24);
***/
#$returndata="$type".'|||'."$realname"; #$returndata="$type".'|||'."$realname";
$data=bin2hex($buffer);
$id=substr($data,0,4);
$flag=substr($data,4,4);
$questions=substr($data,8,4);
$answerRRs=substr($data,12,4);
$authorityRRs=substr($data,16,4);
$additionalRRs=substr($data,20,4);
$startbyte=24;
$dlen=substr($data,$startbyte,2);
$startbyte=26;
$i=1;
while($dlen!='00'){
$domain[$i]=hex2bin(substr($data,$startbyte,hexdec($dlen)*2));
$startbyte=$startbyte+(hexdec($dlen)*2);
$dlen=substr($data,$startbyte,2);
$startbyte=$startbyte+2;
$i++;
}
$realname=join(".",$domain);
$type=substr($data,$startbyte,4);
switch($type){
case '0001':
$type='A';
break;
case '0002':
$type='NS';
break;
case '000c':
$type='PTR';
break;
case '0006':
$type='SOA';
break;
case '001c':
$type='AAAA';
break;
case '0005':
$type='CNAME';
break;
case '0010':
$type='TEXT';
break;
case '000f':
$type='MX';
break;
}
$query=substr($data,24,$startbyte-16);
$returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query")); $returndata= json_encode(array('type' => $type, 'name' => "$realname", 'id'=>"$id", 'query'=>"$query"));
return $returndata; return $returndata;