简体   繁体   中英

PHP Sending Raw Packet

I want to know how I can send packets through the network with raw data. I need to be able to get the Physical addresses of devices on the LAN so I plan on broadcasting or multicasting ARP packets.

Below would be a correctly constructed ARP packet requesting the IP of a device.

0000  00 1e e5 fb a5 21 00 1a  70 dd e1 f2 08 06 00 01   .....!.. p.......
0010  08 00 06 04 00 01 00 1a  70 dd e1 f2 c0 a8 01 01   ........ p.......
0020  00 00 00 00 00 00 c0 a8  01 90                     ........ ..      

This is the raw data in Hexadecimal.

If I was to have the data in ASCII instead is it as simple as opening a socket and sending the information with the correct port number? Actually, since this is Level 2 instead of 3, that would mean no TCP and UDP (I think?) so how would I send this out?

ARP runs on the link layer, TCP sockets and UDP run on IP. PHP can ipen a raw IPv4 socket. using socket_create() . There are examples on the documentation page.

There are also shell tools that CAN construct do this, and from within PHP, you can run them using exec() or related functions.

The exact tool and usage will depend on your operating system, which you haven't mentioned in your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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