The WOL specifications are as follows (WireShark Wiki).
https://wiki.wireshark.org/WakeOnLAN
In short, in the packet
It usually happens. It doesn't matter what the port is, you can see it by matching the pattern, so I think it's possible to detect it with hardware and interrupt it.
So, if you want to send this, I think it's easy to make a UDP packet. There seems to be such a tool, but as far as I did a quick search, there were many that let me specify by IP address. If this is the case, it will be difficult to issue the IP address appropriately. So I implemented a method to directly specify the controller and send it.
Scapy
Use Scapy to generate and send WOL packets. Scapy itself has been written briefly before. Less than
https://qiita.com/ken_hamada/items/736e1c22f6c40702d1a7
I also use Scapy. I think it will probably work on Linux as well.
It's like referring to the code below, or cutting and pasting it based on these. Thank you very much!
ko's blog
https://thinkami.hatenablog.com/entry/2018/01/13/224841
thinkAmi's blog
https://irukanobox.blogspot.com/2017/08/raspberry-pipython3pc.html
It's quicker to look at the code to see how it's actually done, below.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from scapy.all import *
import binascii
# ---->Please set here appropriately.
#Control target. Please specify the real thing for this.
TARGET_MAC_ADDRESS = "11:22:33:44:55:66"
#The IP address to put on the packet. This can be anything.
IP_ADDRESS = "66.77.88.99"
#A controller that creates packets. Please specify the real thing as well.
PCAP_ifname = "en0"
# <-----So far
def issue_WOL():
'''
First, create the payload. As you can see from the code,
Password below(optional)I'm just making something that omits.
https://wiki.wireshark.org/WakeOnLAN
'''
synchronization_stream = b"\xff" * 16
mac_bin = binascii.unhexlify("".join(TARGET_MAC_ADDRESS.split(":")))
payload = synchronization_stream + mac_bin * 16
'''
Generate a WOL packet that sends the above payload as UDP.
'''
ether_layer = Ether(dst=TARGET_MAC_ADDRESS)
ip_layer = IP(dst=IP_ADDRESS)
udp_layer = UDP(sport=44444,dport=33333) #suitable
raw_layer = Raw(load=payload) #The payload can be specified in bytes.
wol_packet = ether_layer / ip_layer / udp_layer / raw_layer
'''
You can use Layer2 because you only have to send the raw package.
If you specify the controller at this time, it should come out from there ...
'''
sendp(wol_packet, iface=PCAP_ifname)
print ("sent WOL ", TARGET_MAC_ADDRESS, IP_ADDRESS)
if __name__ == "__main__":
issue_WOL()
To use it, rewrite TARGET_MAC_ADDRESS, IP_ADDRESS, PCAP_ifname according to your environment and target, and execute this code, and a WOL packet should be output (sudo is required).
IP_ADDRESS does not have to think about the current target address. In fact, even if you specify a messy address, you will receive the following (check with the opposite WireShark). This is because the controller is directly connected because it can be accessed from layer 2.
that's all. Well, with scapy it wasn't too difficult (While writing, Raw (although I was quite addicted to the data model specified by load = ...)
Recommended Posts