Even when this is a network problem, I would say this is rather a Unix/Linux experienced users question.
I am trying to manually send a network magic packet by using echo and redirectors (file descriptors).
This is an example of the data that must be sent via network broadcast (to 255.255.255.255) to wake computer with MAC 00:17:31:3F:D3:A9 (FFFFFFFFFFFF followed by 16 times the MAC without colons):
ffffffffffff0017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a9
I have sent a wake on LAN magic packet from my usual programs (IH WOL, or wakeonlan
tool for Linux) that worked fine, and I captured the network traffic with WireShark:
Note the highlighted green area: the magic packet is correctly sent as Hex.
And now it is time for the redirectors echo method.
I am echoing the magic packet to broadcast IP address, UDP protocol, port number 4000:
exec 6<>/dev/udp/255.255.255.255/4000
echo "ffffffffffff0017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a90017313fd3a9" >&6
No results (remote computer does not wake up). The WireShark's capture is this time slightly different:
As can be seen, the magic packet is now on the right side (!), the supposed binary area
of the info. On the left area, each F
appears as 66
(its ASCII code, I assume), each 0
as 30
… etc.
And, by the way, the data is not detected as "MagicPacket" by WireShark.
What is the correct way to send my data via shell directly to the NIC?
P.S: maybe this question must be transferred to ServerFault? I think it is rather like some sort of hex to ascii or binary conversion issue.
Best Answer
Really easy:
echo -e
for hex to be interpreted. Also you can useprintf
becauseecho
does different things in different shells.Using your same example data:
This time your computer should wake up.
Bash 4.3.39(2)-release (i686-pc-cygwin)
works perfect./dev/protocol/host/port
is not a proper method are completely right. For example, the Hex code\x0a
acts as some control code for network datagrams, splitting the packet. So you can not use MAC address like0a:11:22:33:44:55
with this method. Time to switch tonetcat
orsocat
.