首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在计算机和pydroid 3上运行良好的代码

问在计算机和pydroid 3上运行良好的代码
EN

Stack Overflow用户
提问于 2022-11-30 19:56:53
回答 1查看 30关注 0票数 0

因此,我制作了一个脚本,当我的手机连接到我的wifi网络时,它会自动打开我的计算机,我在另一部手机上下载pydroid来不间断地运行它,它输出:

代码语言:javascript
复制
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

代码是在电脑上工作得很好:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-12-02 14:17:18

在您的手机上运行脚本时,尝试从-t中省略ping。

ping在你的手机上的工作方式不同。在windows上,您必须为其添加-t到ping不停止,在其他操作系统上,这是默认行为。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74633484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档