Created
July 16, 2024 08:37
-
-
Save daisycamber/d552fa3cadc4692d81be3c4b96a5f999 to your computer and use it in GitHub Desktop.
Documents/nfc/nfc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tokens = ['04 64 06 3a 94 51 80'] | |
text_tokens = ['6Ek0ks4DvLo9nZKC8CRnyp8IIlYS6GhigDTi8aNpLbS8gomGw6xtIq2qjk8xQq5pqnFYTotljcnclPvqoIbK8UBrSUR9Mx2YI4itKUMEjBaPf8Afc98ecqHPwynJ99LouhYxSu1QPkRJi414PheuvKW8xTf7MpGHhsFiZdKud1ZhSC7N4MTZGcVlavRvUrAqo22XdINBjmp4SipwIcyETu7KBrfALIKIti3JHeW7itFojKHQiPSsAPRlrM7Fb6bS1Lyk9ypUwSnwf53JneEni32IsDfOTE9AYOxxzfNSGSLfnBWq0isCcs6aLNPTmwWLvjViihi5afEClaJQFUpvDoV1rF94OfTpgtlojsvsu5teIsEkVmeseQSuz4j7U8J32wxClcBurnNr5HDWqnYPUe5uh6AtkVZIzbC3YYpzG8BId3OPPul7FQEM30LEYzO2nWPwzjeX'] | |
user_password = 'da1syG1rl' | |
lock_at_seconds = 60 * 60 #60 * 60 | |
for token in tokens: | |
token = token.replace(':', ' ') | |
token = 'NFCID = ' + token | |
for token in text_tokens: | |
token = token.replace(':', ' ') | |
token = 'Text record: ' + token | |
import logging | |
from websocket_server import WebsocketServer | |
server = WebsocketServer(host='localhost', port=13254, loglevel=logging.INFO) #, key="key.pem", cert="cert.pem") | |
def run(): | |
global server | |
server.run_forever() | |
import os, subprocess, time, threading | |
thread = threading.Thread(target=run) | |
thread.start() | |
from datetime import datetime | |
seconds = (datetime.now() - (datetime.now().replace(minute=0))).total_seconds() | |
subprocess.Popen(['/usr/bin/i3lock'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
def run_process(client): | |
ls = None | |
op = None | |
global seconds | |
global user_password | |
global lock_at_seconds | |
while not op or 'No such' in op: | |
ls = subprocess.Popen(['/usr/bin/ls', '/dev/hidraw2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
op = str(ls.stdout.readline().rstrip(), encoding='utf-8') | |
print('Searching for NXP') | |
seconds += 1 | |
if not seconds < lock_at_seconds: | |
subprocess.Popen(['/usr/bin/i3lock'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
seconds = 0 | |
time.sleep(1) | |
subprocess.Popen(['/usr/bin/sudo', 'chmod', 'a+rw', '/dev/hidraw2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
import asyncio | |
async def main(): | |
primary_index = -1 | |
secondary_index = -2 | |
proc = await asyncio.create_subprocess_exec( | |
'stdbuf', '-o0', "/etc/nxp", | |
stdout=asyncio.subprocess.PIPE, | |
) | |
line = await proc.stdout.readline() | |
while line: | |
print(line.decode()) | |
line = await proc.stdout.readline() | |
decoded = line.decode() | |
for token in tokens: | |
if token in decoded: | |
primary_index = tokens.index(token) | |
# for token in text_tokens: | |
# if token in decoded: | |
# secondary_index = text_tokens.index(token) | |
if primary_index > -1: #secondary_index: | |
subprocess.Popen(['/usr/bin/killall', 'i3lock'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
subprocess.Popen(['/usr/bin/xdotool', 'type', user_password], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
primary_index = -1 | |
secondary_index = -2 | |
client.send_message_to_all(decoded) | |
asyncio.run(main()) | |
while True: | |
while seconds < lock_at_seconds: | |
run_process(server) | |
time.sleep(3) | |
seconds += 3 | |
subprocess.Popen(['/usr/bin/i3lock'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
seconds = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment