Saved,由于原有whoisAPI失效,改用WHOIS命令查询,速度更快,但是需要安装whois命令,RHEL下yum install whois即可

This commit is contained in:
Enoch 2024-01-29 22:00:02 +08:00
parent 2a00928da5
commit 872eabc111
23 changed files with 274 additions and 41 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace app\controller;
include_once base_path().'/vendor/laysense/dns/src/resource/ipv6.php';
use dnstools\ipv6; #用于IPv6相关
/**
* $ipv6=new IPv6;
* $ipv6->ip2bin($ip);
*/
class DnsController
{
public function DNS($type,$name,$rip,$id,$query)
{
#输出信息
#echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n";
#此处请根据业务需要,通过判断$name和$rip返回正确的数据
#详情请参见 https://github.com/ywnsya/workerman-dns 尤其是 https://github.com/ywnsya/Workerman-DNS/blob/master/start.php 中的用法
if($type=='PTR'){
$send['detail']='dns.laysense.com';
$send['ttl']=30;
$send['type']='PTR';
}
if($type=='A'){
$send['type']='A';
$send['detail'][1]='119.29.29.29';
$send['detail'][2]='8.8.8.8';
$send['ttl']=30;
};
if($type=='AAAA'){
$ipv6=new IPv6;
$send['type']='AAAA';
$send['detail'][1]=bin2hex($ipv6->ip2bin("fe80::2c5f")); #此操作可以还原被简化的IPv6地址 协议内不再对IPv6地址进行处理请按照本方式传递16进制无":"的完整16位IPv6
$send['detail'][2]=bin2hex($ipv6->ip2bin("2001:0:2851:b9d0:2c5f:f0d9:21be:4b96"));
$send['ttl']=600;
}
#此处无需修改
$send['id']=$id;
$send['query']=$query;
$return=json_encode($send);
return $return;
}
}

View File

@ -11,12 +11,11 @@ use yzh52521\EasyHttp\Http;
use yzh52521\EasyHttp\Response; use yzh52521\EasyHttp\Response;
use yzh52521\EasyHttp\RequestException; use yzh52521\EasyHttp\RequestException;
class api class api
{ {
public function search(Request $request) public function search(Request $request)
{ {
$content=$request->input('content','0'); $content=trim($request->input('content','0'));
$contenttype=v::ip()->validate($content); $contenttype=v::ip()->validate($content);
if(!$contenttype){ if(!$contenttype){
$contenttype=v::domain(false)->validate($content); $contenttype=v::domain(false)->validate($content);
@ -25,6 +24,9 @@ class api
}else{ }else{
$contenttype='domain'; $contenttype='domain';
$msg['DNS']=dns_get_record("$content",DNS_ANY); $msg['DNS']=dns_get_record("$content",DNS_ANY);
$msg['IP']=gethostbyname("$content");
exec("whois $content",$msg['WHOIS']);
/**
$whois = Http::get('https://api.devopsclub.cn/api/whoisquery?type=json&standard=true', ['domain' => "$content"])->body(); $whois = Http::get('https://api.devopsclub.cn/api/whoisquery?type=json&standard=true', ['domain' => "$content"])->body();
$whois=json_decode($whois); $whois=json_decode($whois);
if($whois->code !=0){ if($whois->code !=0){
@ -46,6 +48,7 @@ class api
$msg['Wx-Safe']=$safe->data->wx; $msg['Wx-Safe']=$safe->data->wx;
$msg['QQ-Safe']=$safe->data->qq; $msg['QQ-Safe']=$safe->data->qq;
} }
**/
} }
}else{ }else{
$contenttype='ip'; $contenttype='ip';

View File

@ -269,7 +269,7 @@
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo($userinfo->name);?></span> <span class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo($userinfo->name);?></span>
<img class="img-profile rounded-circle" <img class="img-profile rounded-circle"
src="<?php echo('https://cravatar.cn/avatar/' . md5(strtolower(trim( $userinfo->email ))));?>"> src="<?php echo('https://headimg.b-cdn.net/' . md5(strtolower(trim( $userinfo->email ))));?>">
</a> </a>
<!-- Dropdown - User Information --> <!-- Dropdown - User Information -->
<div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"

View File

@ -41,7 +41,7 @@ include('common_head.html');?>
<?php <?php
foreach($user as $us){ foreach($user as $us){
$us=json_decode($us); $us=json_decode($us);
$headurl='https://cravatar.cn/avatar/' . md5(strtolower(trim( $us->email ))); $headurl='https://headimg.b-cdn.net/' . md5(strtolower(trim( $us->email )));
$name='name'; $name='name';
$email='email'; $email='email';
$password='password'; $password='password';

View File

@ -35,7 +35,8 @@
"illuminate/events": "^9.45", "illuminate/events": "^9.45",
"yzh52521/webman-throttle": "^1.0", "yzh52521/webman-throttle": "^1.0",
"workerman/validation": "^3.0", "workerman/validation": "^3.0",
"yzh52521/easyhttp": "^1.0" "yzh52521/easyhttp": "^1.0",
"laysense/dns": "^0.0.4"
}, },
"suggest": { "suggest": {
"ext-event": "For better performance. " "ext-event": "For better performance. "

23
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "207e7fe0024016fbc9df51ddb8b5018c", "content-hash": "3edd07c2752c38f6dc9f08d472ff44ca",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
@ -1156,6 +1156,27 @@
}, },
"time": "2022-12-20T14:03:34+00:00" "time": "2022-12-20T14:03:34+00:00"
}, },
{
"name": "laysense/dns",
"version": "0.0.4",
"source": {
"type": "git",
"url": "https://git.laysense.com/enoch/Webman-Dns.git",
"reference": "e6c19f90a14d4b7ef69305b6441889bea545bbce"
},
"type": "library",
"autoload": {
"psr-4": {
"Laysense\\Dns\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Webman plugin laysense/dns. You can making a DNS Server with Webman now",
"time": "2024-01-29T09:20:41+00:00"
},
{ {
"name": "maxmind-db/reader", "name": "maxmind-db/reader",
"version": "v1.11.0", "version": "v1.11.0",

View File

@ -17,5 +17,6 @@ return [
base_path() . '/app/functions.php', base_path() . '/app/functions.php',
base_path() . '/support/Request.php', base_path() . '/support/Request.php',
base_path() . '/support/Response.php', base_path() . '/support/Response.php',
#base_path() . '/phpWhois.org/src/whois.main.php'
] ]
]; ];

View File

@ -0,0 +1,4 @@
<?php
return [
'enable' => true,
];

View File

@ -0,0 +1,10 @@
<?php
return [
'Dns' => [
'handler' => process\DnsProcess::class,
'listen' => 'Dns://0.0.0.0:53',
'transport' => 'udp',
'count' => 4
#cpu_count() * 1
],
];

View File

@ -39,12 +39,4 @@ return [
] ]
] ]
], ],
'Dns' => [
'handler' => process\DnsProcess::class,
'listen' => 'Dns://0.0.0.0:53',
'transport' => 'udp',
'count' => cpu_count() * 4
],
]; ];

View File

@ -15,15 +15,15 @@
return [ return [
#Default保存限流插件和账号密码等dns仅保存DNS信息 #Default保存限流插件和账号密码等dns仅保存DNS信息
'default' => [ 'default' => [
'host' => '121.228.166.201', 'host' => 'localhost',
'password' => 'Qi2005112!', 'password' => 'qi2005112',
'port' => 16379, 'port' => 6379,
'database' => 0, 'database' => 0,
], ],
'dns' => [ 'dns' => [
'host' => '121.228.166.201', 'host' => 'localhost',
'password' => 'Qi2005112!', 'password' => 'qi2005112',
'port' => 16379, 'port' => 6379,
'database' => 1, 'database' => 1,
], ],
]; ];

View File

@ -13,7 +13,7 @@
*/ */
return [ return [
'listen' => 'http://0.0.0.0:8787', 'listen' => 'http://0.0.0.0:4680',
'transport' => 'tcp', 'transport' => 'tcp',
'context' => [], 'context' => [],
'name' => 'webman', 'name' => 'webman',

1
phpWhois.org Submodule

@ -0,0 +1 @@
Subproject commit c0997b4f513d71a139a21d7178616ec28f0733d3

View File

@ -1,6 +1,7 @@
<?php <?php
namespace process; namespace process;
use Workerman\Connection\TcpConnection; use Workerman\Connection\TcpConnection;
use app\controller\DnsController;
class DnsProcess class DnsProcess
{ {
@ -12,6 +13,11 @@ class DnsProcess
$name=$data->name; #查询内容(一般是域名PTR时为倒序IP) $name=$data->name; #查询内容(一般是域名PTR时为倒序IP)
$rip=$connection->getRemoteIp(); #客户端IP $rip=$connection->getRemoteIp(); #客户端IP
#输出信息
#echo "\n Type:$type \n Domain: $name\n Client IP: $rip \n";
$dns=new DnsController;
$return=$dns->DNS($type,$name,$rip,$data->id,$data->query);
$connection->send($return); $connection->send($return);
} }

7
so.php Normal file
View File

@ -0,0 +1,7 @@
<?php
$json = new stdClass();
$json->passwd='A9960454D30A135729BCFC6572776BB12BB20282F2EA1CCE8DBC3040C41ACFC9';
$json->email='ywnsya@126.com';
$json->name='以诺书';
echo json_encode($json);
echo hash("sha256", 'qi2005112');

View File

@ -7,6 +7,29 @@ use yzh52521\EasyHttp\Http;
use yzh52521\EasyHttp\RequestException; use yzh52521\EasyHttp\RequestException;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
$whois = Http::get('https://api.devopsclub.cn/api/whoisquery?type=json&standard=true', ['domain' => "laysense.com"])->body(); declare(ticks = 1);
print_r(json_decode($whois)); function whoislookup($domain){
$whois = new Whois();
$query = $domain;
$result = $whois->Lookup($query,false);
echo '<pre>';
print_r($result);
echo '</pre>';
}
function sig()
{
throw new Exception;
}
try
{
pcntl_alarm(5);
pcntl_signal(SIGALRM, "sig");
whoislookup('layso.de');
pcntl_alarm(0);
}
catch(Exception $e)
{
echo "timeout\n";
}
?> ?>

29
timeout.php Normal file
View File

@ -0,0 +1,29 @@
<?php
declare(ticks = 1);
function a()
{
}
function b()
{
echo "Stop\n";
}
function c()
{
usleep(100000);
}
function sig()
{
throw new Exception;
}
try
{
pcntl_alarm(5);
pcntl_signal(SIGALRM, "sig");
a();
pcntl_alarm(0);
}
catch(Exception $e)
{
echo "timeout\n";
}

View File

@ -38,7 +38,7 @@ return array(
'Respect\\Stringifier\\' => array($vendorDir . '/respect/stringifier/src'), 'Respect\\Stringifier\\' => array($vendorDir . '/respect/stringifier/src'),
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'), 'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/src'), 'Psr\\Log\\' => array($vendorDir . '/psr/log/src'),
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src', $vendorDir . '/psr/http-factory/src'), 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-factory/src', $vendorDir . '/psr/http-message/src'),
'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'), 'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'), 'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
@ -46,7 +46,7 @@ return array(
'MaxMind\\WebService\\' => array($vendorDir . '/maxmind/web-service-common/src/WebService'), 'MaxMind\\WebService\\' => array($vendorDir . '/maxmind/web-service-common/src/WebService'),
'MaxMind\\Exception\\' => array($vendorDir . '/maxmind/web-service-common/src/Exception'), 'MaxMind\\Exception\\' => array($vendorDir . '/maxmind/web-service-common/src/Exception'),
'MaxMind\\Db\\' => array($vendorDir . '/maxmind-db/reader/src/MaxMind/Db'), 'MaxMind\\Db\\' => array($vendorDir . '/maxmind-db/reader/src/MaxMind/Db'),
'Laysense\\Dns\\' => array($vendorDir . '/laysense/dns/src'), 'Laysense\\Dns\\' => array($vendorDir . '/laysense/dns/src', $vendorDir . '/laysense/dns/src'),
'Illuminate\\Support\\' => array($vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/conditionable', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/support'), 'Illuminate\\Support\\' => array($vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/conditionable', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/support'),
'Illuminate\\Redis\\' => array($vendorDir . '/illuminate/redis'), 'Illuminate\\Redis\\' => array($vendorDir . '/illuminate/redis'),
'Illuminate\\Pipeline\\' => array($vendorDir . '/illuminate/pipeline'), 'Illuminate\\Pipeline\\' => array($vendorDir . '/illuminate/pipeline'),

View File

@ -267,8 +267,8 @@ class ComposerStaticInitfdb689ed918f2ee4ecdf1e51d93bd946
), ),
'Psr\\Http\\Message\\' => 'Psr\\Http\\Message\\' =>
array ( array (
0 => __DIR__ . '/..' . '/psr/http-message/src', 0 => __DIR__ . '/..' . '/psr/http-factory/src',
1 => __DIR__ . '/..' . '/psr/http-factory/src', 1 => __DIR__ . '/..' . '/psr/http-message/src',
), ),
'Psr\\Http\\Client\\' => 'Psr\\Http\\Client\\' =>
array ( array (
@ -301,6 +301,7 @@ class ComposerStaticInitfdb689ed918f2ee4ecdf1e51d93bd946
'Laysense\\Dns\\' => 'Laysense\\Dns\\' =>
array ( array (
0 => __DIR__ . '/..' . '/laysense/dns/src', 0 => __DIR__ . '/..' . '/laysense/dns/src',
1 => __DIR__ . '/..' . '/laysense/dns/src',
), ),
'Illuminate\\Support\\' => 'Illuminate\\Support\\' =>
array ( array (

View File

@ -1198,6 +1198,30 @@
}, },
"install-path": "../illuminate/support" "install-path": "../illuminate/support"
}, },
{
"name": "laysense/dns",
"version": "0.0.4",
"version_normalized": "0.0.4.0",
"source": {
"type": "git",
"url": "https://git.laysense.com/enoch/Webman-Dns.git",
"reference": "e6c19f90a14d4b7ef69305b6441889bea545bbce"
},
"time": "2024-01-29T09:20:41+00:00",
"type": "library",
"installation-source": "source",
"autoload": {
"psr-4": {
"Laysense\\Dns\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Webman plugin laysense/dns. You can making a DNS Server with Webman now",
"install-path": "../laysense/dns"
},
{ {
"name": "maximebf/debugbar", "name": "maximebf/debugbar",
"version": "v1.18.1", "version": "v1.18.1",

View File

@ -3,7 +3,7 @@
'name' => 'laysense/highspeaker', 'name' => 'laysense/highspeaker',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '84fc1030a769226c8382dbc9fd171ff45107eaba', 'reference' => '2a00928da5ff5423aef1d1833239266003781e49',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -154,10 +154,19 @@
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'laysense/dns' => array(
'pretty_version' => '0.0.4',
'version' => '0.0.4.0',
'reference' => 'e6c19f90a14d4b7ef69305b6441889bea545bbce',
'type' => 'library',
'install_path' => __DIR__ . '/../laysense/dns',
'aliases' => array(),
'dev_requirement' => false,
),
'laysense/highspeaker' => array( 'laysense/highspeaker' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '84fc1030a769226c8382dbc9fd171ff45107eaba', 'reference' => '2a00928da5ff5423aef1d1833239266003781e49',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),

1
vendor/laysense/dns vendored Submodule

@ -0,0 +1 @@
Subproject commit e6c19f90a14d4b7ef69305b6441889bea545bbce

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;