@Puteulanus #6 不错的示范 😄于是我照猫画虎,经过约 5 轮的对话,免费的 GPT 3.5 为我写了个能 …

@Puteulanus #6 不错的示范 😄于是我照猫画虎,经过约 5 轮的对话,免费的 GPT 3.5 为我写了个能 work 的 PHP 版本:“` $responseIP\n”; }}// 解析 DNS 请求function dns_parse_message($data){ $dnsHeader = unpack(‘nid/nflags/nqdcount/nancount/nnscount/narcount’, substr($data, 0, 12)); $question = []; $offset = 12; for ($i = 0; $i rtrim($questionName, ‘.’), ‘qtype’ => isset(unpack(‘ntype’, substr($data, $offset, 2))[‘type’]) ? unpack(‘ntype’, substr($data, $offset, 2))[‘type’] : ”, ]; $offset += 4; } return [ ‘header’ => $dnsHeader, ‘question’ => $question, ];}// 构建 DNS 响应function dns_build_response($request, $ip){ $header = pack(‘nnnnnn’, $request[‘header’][‘id’], 0x8180, 1, 1, 0, 0); $question = ”; foreach ($request[‘question’] as $q) { $question .= dns_compress_name($q[‘qname’]) . pack(‘nn’, 1, 1); } $answer = dns_compress_name($request[‘question’][0][‘qname’]) . pack(‘n*’, 1, 1, 0, 1, 0, 4); // 响应类型为 A 记录,TTL 为 0 ,数据长度为 4 $answer .= inet_pton($ip); // 将 IP 地址转换为二进制格式 return $header . $question . $answer;}// 辅助函数,检查字符串结尾function endsWith($haystack, $needle){ return substr($haystack, -strlen($needle)) === $needle;}// 辅助函数,压缩 DNS 消息中的域名function dns_compress_name($name){ $parts = explode(‘.’, $name); $compressedName = ”; foreach ($parts as $part) { $compressedName .= chr(strlen($part)) . $part; } return $compressedName . “\x00”;}?>“`

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索