Get the MAC address of a magic packet

Good evening everyone,
I am trying to retrieve in a text file the MAC address of the pc that I want to wake up with a wake On Lan.
when i am on my server and i run the following command

root@localhost# tcpdump -UlnXi eth0 proto 0x0842 or udp port 9 2>/dev/null | sed -nE 's/^.*20:  (ffff|.... ....) (..)(..) (..)(..) (..)(..).*$/\2:\3:\4:\5:\6:\7/p'

i see on the screen the MAC address of the pc but now I want to put this MAC address in a file called mac.txt and I can’t do it

Thanks for your help


Why don’t you simply redirect the output into a file?

tcpdump options | sed options > mac.txt

Why do you get the MAC from tcpdump?

  • Don’t you have access to the physical device / know its MAC?
  • Don’t you have IP address of the device? If you know the address, then
ping -c 1 $ADDR
ip neigh | grep $ADDR
ip neigh | grep $ADDR | cut -d' ' -f 5 > mac.txt

thank you jlehtone for answering me,

in fact I send with a web application a wake on lan to a pc and that’s where I want to recover the destination of MAC address.

when i do the command

tcpdump options | sed options > mac.txt

i get an empty mac.txt file, that’s exactly my problem

Thank you