因此,我制作了一个脚本,当我的手机连接到我的wifi网络时,它会自动打开我的计算机,我在另一部手机上下载pydroid来不间断地运行它,它输出:
ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination代码是在电脑上工作得很好:
import subprocess
from wakeonlan import send_magic_packet
IP_DEVICE = 'phonesip'
devices = {
'my_pc': {'mac': 'mymacadress', 'ip_address': 'myipadress'}
}
def wake_device(device_name):
if device_name in devices:
mac, ip = devices[device_name].values()
send_magic_packet(mac, ip_address=ip)
print('Magic Packet Sent')
else:
print('Device Not Found')
proc = subprocess.Popen(["ping", '-t', IP_DEVICE], stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if not line:
break
else:
None
try:
connected_ip = line.decode('utf-8').split()[2].replace(':', '')
if connected_ip == IP_DEVICE:
print('Device connected!')
wake_device('my_pc')
# Do whatever you want when the device connects here...
break
else:
print('Pinging device...')
except:
pass发布于 2022-12-02 14:17:18
在您的手机上运行脚本时,尝试从-t中省略ping。
ping在你的手机上的工作方式不同。在windows上,您必须为其添加-t到ping不停止,在其他操作系统上,这是默认行为。
https://stackoverflow.com/questions/74633484
复制相似问题