php实现不同地区dns服务器域名解析ip地址结果查询工具
代码语言:php
所属分类:其他
代码描述:php实现不同地区dns服务器域名解析ip地址结果查询工具
代码标签: php 不同 地区 dns 服务器 域名 解析 ip 地址 结果 查询 工具
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php // 定义DNS服务器列表和解析函数 $global_dns_servers = array( '中国大陆' => array( '阿里DNS' => '223.5.5.5', 'DNSPod' => '119.29.29.29' ), '中国香港' => array( 'HKDNS' => '203.198.7.66', 'HGC DNS' => '218.102.23.228' ), '中国台湾' => array( 'TWNIC DNS' => '101.101.101.101', 'HiNet DNS' => '168.95.1.1' ), '日本' => array( 'JPRS DNS' => '203.119.1.1', 'IIJ DNS' => '202.232.2.1' ), '韩国' => array( 'KT DNS' => '168.126.63.1', 'SK DNS' => '210.220.163.82' ), '新加坡' => array( 'SingNet DNS' => '165.21.83.88', 'Starhub DNS' => '203.116.1.78' ), '美国' => array( 'Google DNS' => '8.8.8.8', 'Cloudflare' => '1.1.1.1' ), '俄罗斯' => array( 'Yandex DNS' => '77.88.8.8', 'RU-Center' => '193.58.251.251' ), '德国' => array( 'DNS.WATCH' => '84.200.69.80', 'Freenom DNS' => '80.80.80.80' ), '英国' => array( 'BT DNS' => '194.72.0.114', 'Virgin Media' => '194.168.4.100' ), '法国' => array( 'Orange DNS' => '194.126.130.10', 'FDN DNS' => '80.67.169.12' ), '印度' => array( 'BSNL DNS' => '218.248.255.141', 'Airtel DNS' => '202.138.120.4' ), '澳大利亚' => array( 'Telstra DNS' => '139.130.4.4', 'Optus DNS' => '198.142.0.51' ) ); function resolve_domain($domain, $dns_server) { $result = array(); $start_time = microtime(true); $context = stream_context_create([ 'socket' => [ 'timeout' => 3.0 ] ]); putenv("RES_OPTIONS=nameserver $dns_server"); try { $dns = dns_get_record($domain, DNS_A); $response_time = round((microtime(true) - $start_time) * 1000); if($dns) { $result['ip'] = $dns[0]['ip']; $result['response_time'] = $response_time; $result['dns_server'] = $dns_server; } else { $result['ip'] = '无法解析'; $result['response_time'] = 0; $result['dns_server'] = $dns_server; } } catch (Exception $e) { $result['ip'] = '解析错误'; $result['response_time'] = 0; $result['dns_server'] = $dns_server; } return $result; } // 处理POST请求 if(isset($_POST['domain'])) { $domain = $_POST['domain']; $results = array(); foreach($global_dns_servers as $country => $servers) { $first_server = reset($servers); if($first_server !== false) { $server_name = key($servers); $server_ip = $first_server; $results[$country] = resolve_domain($domain, $server_ip); } } header('Content-Type: application/json'); echo json_encode($results, JSON_UNESCAPED_UNICODE); exit; } ?> <!DOCTYPE html> <html> <head> <t.........完整代码请登录后点击上方下载按钮下载查看
网友评论0