将 DHCP 特定的供应商选项发送到 Windows 服务器

将 DHCP 特定的供应商选项发送到 Windows 服务器

我的目标是向 Windows 机器发送一些信息(url 和一次性令牌)。它对 GNU/Linux 服务器运行良好,因为我从 /var/lib/dh​​cp/dhcp.lease 或类似文件中获取信息。这是我的设置:

dhcp 服务器(GNU/Linux 服务器):

host windows {
            dynamic;
            hardware ethernet XX:XX:XX:XX:XX:XX;
            fixed-address 10.70.10.107;
            supersede vendor-encapsulated-options  "http://URL/TOKEN";
    }

我发现在 Windows 服务器上获取此信息的唯一方法是通过注册表。正如我添加的这里在 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces{ID} 下,您可以找到名为Dhcp接口选项

问题在于此密钥上的信息已“损坏”。我会尽力解释。

使用 Wireshark,我可以看到来自 DHCP 服务器的格式良好的 DHCP 应答,其中包含 43 个选项。此选项包含我所寻找的内容。当我尝试在注册表中读取它时,发现其中包含大量垃圾信息,并且 URL 的某些部分缺失。

DHCP 选项 RFC 2132定义以下协议:

Code   Len   Vendor-specific information
+-----+-----+-----+-----+---
|  43 |  n  |  i1 |  i2 | ...
+-----+-----+-----+-----+---

我观察到 Windows 在获取选项后做了类似的事情。我的意思是,如果 URL 是“http://URL/TOKEN”,Windows 会将“h”设置为 ID,将“t”设置为长度,并在第二个“t”之后开始读取。我的 URL 比最后一个 ASCII 可打印字符 (~) 长,我无法对此采取任何解决方法。

更新 1

WireShark 捕获:

Option: (t=43,l=16) Vendor-Specific Information
  Option: (43) Vendor-Specific Information
  Length: 16
  Value: 687474703a2f2f55524c2f544f4b454e (http://URL/TOKEN)

Windows 注册表:

"DhcpInterfaceOptions"=hex:06,00,00,00,00,00,00,00,08,00,00,00,00,00,00,00,52,\
 45,b7,4f,0a,46,0a,01,08,08,08,08,03,00,00,00,00,00,00,00,04,00,00,00,00,00,\
 00,00,52,45,b7,4f,0a,46,0a,01,0f,00,00,00,00,00,00,00,0f,00,00,00,00,00,00,\
 00,52,45,b7,4f,74,50,1f,2b,6f,61,6f,75,75,6a,3f,64,6e,77,2e,00,01,00,00,00,\
 00,00,00,00,04,00,00,00,00,00,00,00,52,45,b7,4f,ff,ff,ff,00,36,00,00,00,00,\
 00,00,00,04,00,00,00,00,00,00,00,52,45,b7,4f,0a,46,0a,01,35,00,00,00,00,00,\
 00,00,01,00,00,00,00,00,00,00,52,45,b7,4f,05,00,00,00,fc,00,00,00,00,00,00,\
 00,00,00,00,00,00,00,00,00,2a,bd,b6,4f,33,00,00,00,00,00,00,00,04,00,00,00,\
 00,00,00,00,52,45,b7,4f,00,00,8c,a0

更新 2

如果 URL 比定义的大小短Windows 协议,url 不会显示在注册表中。在我的例子中,“h”是标识符,“t”是大小 (116)。如果 url 是:

http://AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

注册表包含我之前粘贴的内容。url 正好是 117 个字符,但我们对 id 和大小使用了 2。这意味着数据是 115。不够。

如果我在我的网址中添加一个“A”:

http://AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

然后注册表包含:

"DhcpInterfaceOptions"=hex:68,00,00,00,00,00,00,00,74,00,00,00,01,00,00,00,62,\
0e,bb,4f,74,70,3a,2f,2f,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,\
41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,\
41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,\
41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,\
41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,06,00,00,00,00,00,\
00,00,08,00,00,00,00,00,00,00,62,0e,bb,4f,0a,46,0a,01,08,08,08,08,03,00,00,\
00,00,00,00,00,04,00,00,00,00,00,00,00,62,0e,bb,4f,0a,46,0a,01,0f,00,00,00,\
00,00,00,00,0f,00,00,00,00,00,00,00,62,0e,bb,4f,75,61,4a,1f,31,4c,ca,11,55,\
6f,2e,63,1f,6d,fe,00,01,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,62,0e,\
bb,4f,ff,ff,ff,00,33,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,62,0e,bb,\
4f,00,00,8c,a0,36,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,62,0e,bb,4f,\
0a,46,0a,01,35,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,62,0e,bb,4f,05,\
00,00,00

41 是“A”的十六进制表示。

答案1

实施的解决方案是:

dhcpd.conf:

option space yourCompany;
    option yourCompany.url code 128 = text;

class "vendor-classes" {
    match option vendor-class-identifier;
}

subclass "vendor-classes" "MSFT 5.0" {
    vendor-option-space yourCompany;
}

在您的租约上添加以下一行:

supersede yourCompany.url = "http://URL"

您可以根据需要更改 .url。只需确保在公司空间中更改选项名称即可。

使用此方法我可以看到注册表上的完整 URL。

答案2

我认为 supersede 对于服务器配置来说不正确。通常它由 dhcp 客户端配置使用。

尝试将其添加到您的 dhcpd 配置中,看看是否可以在注册表中看到这些选项

option space ISC code width 1 length width 1 hash size 3; 
option ISC.sample code 1 = text; 
option vendor.ISC code 2495 = encapsulate vivso-sample; 
option vendor-class.ISC code 2495 = text;

option ISC.sample "configuration text here"; 
option vendor-class.ISC "vendor class here";

相关内容