My home network diagram is simple as below:
internet --> Optical modem --> router --> pc1 ,pc2 111.111.111.111--> 192.168.1.1 -->192.168.31.1 --> 192.168.31.144,192.168.31.173 The ISP provide a static ip ,supposing it's 111.111.111.111,optical modem's ip address is 192.168.1.1,router's ip address is 192.168.31.1, ip address for pc1 is 192.168.31.144 , ip address for pc2 is 192.168.31.173,the pc1's mac address is xx.xx.xx.xx.
The openwrt is running on my router,adding some port forwarding rules in the router and open firewall:
forwarding rule name protocl outer port inner IP address inner port wakeonwan UDP 9 192.168.31.144 9 ssh TCP and UDP 10000 192.168.31.1 22 And bind the ip address and mac in openwrt:
ip address mac interface 192.168.31.144 xx.xx.xx.xx ?? Which interface to choose from the below options?
Login my router remotely:
ssh [email protected] -p 10000 Issue wol command from the router:
/usr/bin/wol -i 192.168.31.255 xx.xx.xx.xx The pc1 can be waked on from the router!
Turn off pc1,wakeup it from pc2 with the following python code wakeonlan.py:
from wakeonlan import send_magic_packet send_magic_packet('xx.xx.xx.xx') Executing the command python3 wakeonlan.py in pc2 can wakeup my pc1 successfully.
Executing the command python3 wakeonwan.py remotely(for example--in my company's pc) can't wakeup my pc1.
cat wakeonwan.py mac = "xx.xx.xx.xx" target_ip = "111.111.111.111" from wakeonlan import send_magic_packet send_magic_packet(mac, ip_address=target_ip,port=9) It encounter no error,why pc1 can't wakeup with wakeonwan.py?
Let's do it with a lib--paramiko.
pip install paramiko Eidt wakeonwan-paramiko.py:
import paramiko from contextlib import contextmanager host = '111.111.111.111' username = 'root' password = 'password' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, username=username, password=password,port=10000) stdin, stdout, stderr = ssh.exec_command("/usr/bin/wol -i 192.168.31.255 xx:xx:xx:xx") ssh.close() python3 wakeonwan-paramiko.py can wakeup my home pc from external network,i feel it is more simple to edit wakeonwan.py to wakeup pc remotely?
How to fix it?
