Aplicação gráfica para Wake-on-LAN com Python 3 + GUI Tk/Tcl
Publicado por Fernando (última atualização em 18/11/2013)
[ Hits: 5.456 ]
Homepage: https://github.com/phoemur/
Estou começando a aprender programar GUI e fiz essa interface para o protocolo Wake-on-LAN em Python 3 utilizando Tkinter + Ttk.
Peguei a função WOL já pronta e implementei a GUI.
Requer: Python > 3.1.
Façam bom uso.
#!/bin/env python3
#
# Written by phoemur - nov / 2013
#
# Thanks to ActiveState Code Recipes:
# http://code.activestate.com/recipes/358449-wake-on-lan/
# and
# http://code.activestate.com/recipes/577609-wake-on-lan-for-python-3/
import socket, struct
from tkinter import *
from tkinter import ttk, messagebox
def wake_on_lan(*args):
""" Switches on remote computers using WOL.
"""
try:
macaddress = str(mac.get()).upper()
broadcast = str(broad.get())
except:
pass
# Check macaddress format and try to compensate
if len(macaddress) == 12:
pass
elif len(macaddress) == 12 + 5:
sep = macaddress[2]
macaddress = macaddress.replace(sep,'')
else:
messagebox.showinfo(message='Incorrect MAC Address format', title='Warning')
return
# Pad the synchronization stream
data = b'FFFFFFFFFFFF' + (macaddress * 20).encode()
send_data = b''
# Split up the hex values in pack
for i in range(0, len(data), 2):
send_data += struct.pack('B', int(data[i: i + 2], 16))
# Broadcast it to the LAN
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(send_data, (broadcast, 7))
def make_menu(w):
global the_menu
the_menu = Menu(w, tearoff=0)
the_menu.add_command(label="Cut")
the_menu.add_command(label="Copy")
the_menu.add_command(label="Paste")
def show_menu(e):
w = e.widget
the_menu.entryconfigure("Cut", command=lambda: w.event_generate("<<Cut>>"))
the_menu.entryconfigure("Copy", command=lambda: w.event_generate("<<Copy>>"))
the_menu.entryconfigure("Paste", command=lambda: w.event_generate("<<Paste>>"))
the_menu.tk.call("tk_popup", the_menu, e.x_root, e.y_root)
# Start our GUI
root = Tk()
root.title("Py3k - Wake-On-LAN")
root.resizable(FALSE,FALSE)
make_menu(root)
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
mainframe['relief'] = 'raised'
mac = StringVar()
mac.set('AA:BB:CC:DD:EE:FF')
broad = StringVar()
broad.set('255.255.255.255')
mac_entry = ttk.Entry(mainframe, width=17, textvariable=mac)
mac_entry.grid(column=2, row=1, sticky=(W, E))
broad_entry = ttk.Entry(mainframe, width=15, textvariable=broad)
broad_entry.grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Wake-On-LAN", command=wake_on_lan).grid(column=3, row=3, sticky=W)
ttk.Button(mainframe, text = "QUIT", command=root.quit).grid(column=1, row=3, sticky=E)
ttk.Label(mainframe, text="MAC Address: ").grid(column=1, row=1, sticky=(W, E))
ttk.Label(mainframe, text="Broadcast Address: ").grid(column=1, row=2, sticky=(W, E))
for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)
mac_entry.focus()
root.bind('<Return>', wake_on_lan)
root.bind("<Button-3><ButtonRelease-3>", show_menu)
root.mainloop()
Envio de comandos por ssh sem troca de chaves a múltiplos servidores
Importar múltiplos hosts ZABBIX
verifySite - um verificador de sites
Ligando máquina pela rede usando Python
Nenhum comentário foi encontrado.
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Novos apps de produtividade, avanços em IA e distros em ebulição agitam o universo Linux
Como instalar o repositório do DBeaver no Ubuntu
Como instalar o Plex Media Server no Ubuntu
Digitando underscore com "shift" + "barra de espaços"
Como ativar a lixeira e recuperar aquivos deletados em um servidor Linux
Como mudar o nome de dispositivos Bluetooth via linha de comando
dpkg: erro: gatilho de arquivo duplicado chamado pelo arquivo de nome (6)
Instalação não está resolvendo as dependencias (2)
Captação de áudio no zorin linux começa a diminuir com o tempo (5)
Alternativas ao Multilogin para gerenciamento de múltiplas contas/prof... (0)









