python-WOL唤醒-使用flet开发的页面

使用python和flet进行开发一个小页面:

博主使用的iOS手机,这个页面部署在一个机顶盒里面,使用wg进行访问内网网页WOL唤醒电脑。

我的电脑大概5秒左右就启动成功了,python代码里面使用from pythonping import ping进行ping也可以等待ping通后进行远程操作,博主使用的RDP远程桌面进行控制的。

https://flet.dev/

flet创建的页面属于PWA页面,可以生成一个桌面快捷方式。也可以使用flet的app

Testing Flet app on iOS

Start building awesome mobile apps in Python using just your computer and mobile phone!

Install Flet app to your iOS device. You will be using this app to see how your Flet project is working on iPhone or iPad.

https://flet.dev/docs/guides/python/testing-on-ios

img

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import flet as ft
from flet_core import padding
from wakeonlan import send_magic_packet
from time import sleep
from pythonping import ping


def main(page: ft.Page):
page.title = "WOL启动"
target_host = "你的IP"

def wol_start(e):
mac_address = '你的mac地址'
send_magic_packet(mac_address)
isTrue = False
for i in range(30):
response_list = ping(target_host, count=1)
for response in response_list:
print(response)
page.add(ft.Text(f"{response},{i}!"))
if response.success:
isTrue = True
break
if isTrue:
page.clean()
initstart()
page.add(ft.Text(f"启动成功~~~"))
break
sleep(0.5)
sleep(1)
page.clean()
initstart()
print("ok")

def initstart():
page.add(
ft.ResponsiveRow([
ft.Container(
ft.ElevatedButton(text="WOL-Start-myPC", on_click=wol_start),
padding=padding.only(top=55)

),
])
)

initstart()


# ft.app(target=main)

ft.app(target=main, host='0.0.0.0', port=8080, view=ft.AppView.WEB_BROWSER)

github gist地址

https://gist.github.com/landv/3e5961f6c3f44e66c4afe3ebd2aa26bd

image-20240326160951804