Salutations aux amateurs de python. Une fois, j'ai accidentellement coincé mon doigt dans des ctypes. Et vous savez, j'ai bien aimé. Surtout le bloc d'entrée clavier et souris. Et la première chose qui m'est venue à l'esprit était: "Pourquoi ne pas écrire un casier pour Windows en python, avec un déverrouillage sur une clé USB, comme une clé" (ne me demandez pas pourquoi, je ne me connais pas). Et puis mon imagination est partie. Maintenant, je vais écrire ce que vous devez affronter pour l'écrire.
Eh bien, commençons!
La première étape consiste à créer une partie graphique du casier. Nous ne ferons pas une feuille bêtement blanche: d
Nous la nommerons. ... ... locker.pyw
Pourquoi pyw? Oui, car lorsque vous démarrez le casier, la console sortira, qu'un mauvais oncle potentiel peut fermer, alors tout le casier sera couvert, mais nous n'en avons pas besoin.
import hashlib
import time
import sys
import os
from tkinter import Tk, Entry, Label
import tkinter
import pyautogui
import threading
from lofu import *
Importation de bibliothèques pour locker.pyw
* hashlib nous devons enregistrer la clé sous forme de hachage, donc il y a moins de risque de rebut (si vous n'en avez pas besoin, vous n'avez pas à l'importer!)
* le temps est juste pour dormir ()
* sys pour une sortie agréable ()
* os pour démarrer la tâche de la partie système () du casier
* tkinter c'est notre partie graphique
* pyautogui pour déplacer la souris dans un coin (laissez-le penser à son comportement)
* threading pour le deuxième thread de décalage de la souris (afin de ne pas interférer avec le thread principal)
* lofu. ... ... ... J'ai mis quelques fonctions, juste dans un autre fichier et c'est tout, je suis un artiste, comme je le vois!
Faisons la fonction de déplacer la souris sur le côté pour que l'utilisateur n'ait pas le temps de cliquer n'importe où.
def mouse_trac(screen_width, screen_height):
while True:
pyautogui.moveTo(screen_width, screen_height)
pyautogui.moveTo(screen_width, screen_height) - ( , )
screen_width, screen_height
Tk(), ,
root = Tk()
root.attributes('-fullscreen', True)
pyautogui.FAILSAFE = False
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.attributes('-fullscreen', True) - .
pyautogui.FAILSAFE = False - , .
screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() - ,
,
x = threading.Thread(target=mouse_trac, args=(screen_width, screen_height), daemon=True)
x.start()
target=mouse_trac - ,
args=(screen_width, screen_height) -
daemon=True -
label = Label(root, text='Enter flesh drive with code!', font='Courier 15', fg='#C71585')
label.place(relx=.5, rely=.94, anchor="center")
label3 = Label(root, text='USBCODE waiting...', font='Courier 20', fg='#00BFFF')
label3.place(relx=.5, rely=.40, anchor="center")
label4 = Label(root, text='Powered by .... wait....by who?', font='Courier 15', fg='#C71585')
label4.place(relx=.1, rely=.95, anchor="center")
root.update()
label = Label(root, text='Enter flesh drive with code!', font='Courier 15', fg='#C71585') label.place(relx=.5, rely=.94, anchor="center") -
root -
text - :G
font -
fg - HTML ( https://colorscheme.ru/html-colors.html )
relx - X
rely - Y
anchor="center" -
root.update() - ( CTRL+S)
.
.
, . , " " , windows. windows " ". , , . ( , , ).
" "
"" ( )
" "
, ""
""
: " " " (, 1 , )"
""
" "
! ? . . .
. input_block.pyw
from ctypes import *
import time
import sys
from lofu import *
while True:
statusl = status_lock()
if str(statusl) == '0':
windll.user32.BlockInput(False)
elif str(statusl) == '1':
windll.user32.BlockInput(True)
lofu
def status_lock():
filee = open(r' ', 'r')
return filee.read()
filee.close()
def disable_lock():
filee = open(r' ', 'w')
text = 0
filee.write(str(text))
filee.close()
def enable_lock():
filee = open(r' ', 'w')
text = 1
filee.write(str(text))
filee.close()
, : " , ? JSON ! !"
json, sqlite3 . . . !
input_block.pyw >> input_block.exe
pyinstaller
pyinstall input_block.pyw --onefile
? pyinstaller?
pip install pyinstaller
" ".
" " " " .
locker.pyw
os.system('schtasks.exe /run /tn " "')
, ,
while True:
try:
enable_lock()
file = open(r'F:\key.txt','r')
file_t = str(file.read())
file.close()
hash_object = hashlib.sha256(file_t.encode())
hex_dig = hash_object.hexdigest()
if ' -' == str(hex_dig):
label3.configure(text='USBCODE correct. Unlocking...', fg='#00FF00', font="Courier 30")
root.update()
time.sleep(4)
disable_lock()
sys.exit()
else:
label3.configure(text='USBCODE incorrect. Try again!', fg='#FF0000', font="Courier 30")
enable_lock()
root.update()
except SystemExit:
sys.exit()
except:
time.sleep(10)
label3.configure(text='USBCODE not found! Waiting...', fg='#FF1493', font="Courier 20")
enable_lock()
root.update()
, . ,
enable_lock() - lofu
disable_lock() - lofu -
time.sleep(N) -
file = open(r'F:\key.txt','r')
file_t = str(file.read())
file.close() - ,
hash_object = hashlib.sha256(file_t.encode())
hex_dig = hash_object.hexdigest() -
if ' ' == str(hex_dig): - :d
:
* - ( , , , )
* ( )
* ( - locker.pyw)
, locker.pyw.
, shell:startup, " ".
C'est tout. Mes félicitations! Nous venons de réaliser un casier pour Windows en Python 3.xc avec blocage complet des entrées via le "Task Scheduler" , avec déverrouillage via une clé USB, avec une clé de hachage et une interface graphique!
PS Vous pouvez également mettre dans le raccourci locker.pyw dans le champ " Raccourci " pour lier les touches pour un verrouillage rapide.