简体   繁体   English

如何从DHCP数据包中提取客户端数据?

[英]How to extract client data from DHCP packet?

I need to develop router software that displays something like this (Note: This post is related to network-programming): 我需要开发显示如下所示的路由器软件(注意:这篇文章与网络编程有关):

在此处输入图片说明

I captured DHCP packets through Wireshark and observed that it contains all the details I need to display. 我通过Wireshark捕获了DHCP数据包,并观察到它包含我需要显示的所有详细信息。 The data looks like this: 数据如下所示:

在此处输入图片说明

I checked the same with dhcpdump and tcpdump tools. 我用dhcpdump和tcpdump工具进行了检查。

me@linux:$ sudo dhcpdump -i wlp6s0

Part of the output I am interested in is: 我感兴趣的部分输出是:

  TIME: 2016-06-23 12:20:50.976
    IP: 10.42.0.1 (b0:c0:90:69:72:57) > 10.42.0.99 (fc:64:ba:1b:40:e5)
    OP: 2 (BOOTPREPLY)
 HTYPE: 1 (Ethernet)
  HLEN: 6
  HOPS: 0
   XID: e277d896
  SECS: 0
 FLAGS: 0
CIADDR: 0.0.0.0
YIADDR: 10.42.0.99
SIADDR: 10.42.0.1
GIADDR: 0.0.0.0
CHADDR: fc:64:ba:1b:40:e5:00:00:00:00:00:00:00:00:00:00
 SNAME: .
 FNAME: .
OPTION:  53 (  1) DHCP message type         5 (DHCPACK)
OPTION:  54 (  4) Server identifier         10.42.0.1
OPTION:  51 (  4) IP address leasetime      3600 (60m)
OPTION:  58 (  4) T1                        1800 (30m)
OPTION:  59 (  4) T2                        3150 (52m30s)
OPTION:   1 (  4) Subnet mask               255.255.255.0
OPTION:  28 (  4) Broadcast address         10.42.0.255
OPTION:   6 (  4) DNS server                10.42.0.1
OPTION:   3 (  4) Routers                   10.42.0.1
---------------------------------------------------------------------------

But without using these tools (those tools can't be added on router board), how to extract client data like MAC address, IP address and other information from dhcp packet (or how those tools extracted the information) programmatically (if possible in C)? 但是,如果不使用这些工具(不能在路由器板上添加这些工具),如何以编程方式(如果可能的话,在C语言中)从dhcp数据包中提取客户端数据(例如MAC地址,IP地址和其他信息)(或这些工具如何提取信息) )?

Assuming your DHCP server does not provide any means to get the information you need, you can use a socket of type: 假设您的DHCP服务器没有提供任何获取所需信息的方法,则可以使用以下类型的套接字:

socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))

With it you will be able to see all ETH packets and process them same as wireshark. 有了它,您将能够查看所有ETH数据包,并像wireshark一样处理它们。 You will need some knowledge of OSI layers (ETH2, IP, UDP and DHCP) in order to process the headers and content from the packets. 您将需要一些OSI层知识(ETH2,IP,UDP和DHCP),以便处理数据包中的标头和内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM