PHP:读取包含UDP数据包的二进制文件
我有一个程序,它监听其他程序发送的一些 udp 数据包并将其保存到文件中。我需要在 php 中创建一个解析器,以准备好从正在侦听的其他程序捕获的信息。
我正在尝试使用 un_pack 获取 UDP 标头,从中我可以获取内容,但端口和长度标头与程序提供给我的当前日志不匹配,所以我认为我做错了什么。我对这类东西有点陌生,但下面是我正在发生的事情。
$i = 0;
$sourceport = unpack("S", $content[$i++].$content[$i++]);
$targetport = unpack("S", $content[$i++].$content[$i++]);
$length = unpack("S", $content[$i++].$content[$i++]);
$checksum = unpack("S", $content[$i++].$content[$i++]);
哦,还有一件事,我真的不知道如何解析数据,它只是纯文本还是我需要用它做其他事情?
I have a program which listens to some udp packets being sent by other programs and saves it to a file. I need to make a parser in php to ready in the information which was captured from the other program which was listening.
I am attempting to use un_pack to get the UDP header, from which I could get the contents, but the ports and length headers do not match up with the current logs that the program is giving me so I think I am doing something wrong. I am kinda new to this kind of stuff, but bellow is what I have going on.
$i = 0;
$sourceport = unpack("S", $content[$i++].$content[$i++]);
$targetport = unpack("S", $content[$i++].$content[$i++]);
$length = unpack("S", $content[$i++].$content[$i++]);
$checksum = unpack("S", $content[$i++].$content[$i++]);
Oh and one more thing, I don't really know how to parse the data, will it just be in plain text or will I need to do something else with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上取决于程序如何将 UDP 数据包保存到文件中。我建议您查看该文件,并将其与您期望在 UDP 数据包中看到的值进行比较。如果您无法理解要读取的文件的格式,您将无法编写程序来解析它。
It really depends on how the program saves the UDP packets to the file. I suggest you look at the file, and compare it to the values you would expect to see in a UDP packet. If you can't understand the format of the file you're trying to read, you won't be able to write a program to parse it.