创建名称服务器十六进制标头 [英] create nameserver hex header

查看:44
本文介绍了创建名称服务器十六进制标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须向名称服务器发出请求.socketpart 就像一个魅力,但创建包我有一些问题.

I have to make a request to a nameserver. the socketpart is working like a charm, but to create the package I have some problems.

$domainname = "google.nl";

$hexdomain = ascii2he($domainname);

$package = "\x01\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x0b".$hexodmain."\x00\x00\xff\x00\x01";

这应该是我发送到名称服务器的包,但包不正确.什么是创建 $package

this should be the package i send to the nameserver but the package is not correct. what is the right way to create $package

推荐答案

首先,你传递给名称服务器的名称不是点分隔的,而是名称的每一部分单独传输.

First, the name you pass to the nameserver is not dot-separated, but every part of the name is transmitted separately.

其次,您不发送转换为十六进制的数据,而是直接发送它们.十六进制 (\x01\x01) 只是表示.

Second, you do not send the data converted to hex, but send them directly. The hex (\x01\x01) is just the representation.

因此,您将以 "\x06google\x02nl\x00" 的形式对 google.nl 进行编码,因为每个名称部分前面都有其长度,并且最后一个是 \x00 表示空字符串 - 这反过来表示名称链的末尾.

So you would encode your google.nl in the form "\x06google\x02nl\x00", as each of the name parts is preceded by its length, and the last one is succeeded by a \x00 meaning the empty string - which in turn denotes the end of the names chain.

因此,为了保持可变性,您应该将域名拆分为多个组件,并在每个组件之前添加相应的长度字节.

So in order to remain variable, you should split your domain name into its components and precede each of them with the corresponding length byte.

类似的东西

function domain2dns($domain)
{
    $split = explode(".", $domain);
    $target = ""; // cumulate here
    foreach ($split as $part) {
        // For every $part, prepend one byte denoting its length.
        // strlen($part) is its length which is supposed to be put into one character.
        $target .= chr(strlen($part)).$part;
    }
    return $target . "\x00";
}

可能有用

$domainname = "google.nl";

$dnsdomain = domain2dns($domainname);

$package = "\x01\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00" . $dnsdomain . "\x00\xff\x00\x01";

这篇关于创建名称服务器十六进制标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆