forked from gm-stack/overlook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_rfid_kbd.py
54 lines (49 loc) · 1.34 KB
/
win_rfid_kbd.py
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
52
53
54
from serial import Serial
from rdm880 import *
import MySQLdb, MySQLdb.cursors
import time
import win32com.client
import ConfigParser
import sys
config = ConfigParser.ConfigParser()
config.read("win_rfid_kbd.ini")
print "connecting to MySQL"
conn = MySQLdb.connect( host=config.get("mysql","host"),
user=config.get("mysql","user"),
passwd=config.get("mysql","passwd"),
db=config.get("mysql","db"),
cursorclass=MySQLdb.cursors.DictCursor, charset='utf8')
cursor = conn.cursor()
print "connected"
shell = win32com.client.Dispatch("WScript.Shell")
def checkCard(cardid_hex):
print "card id is " + cardid_hex
cursor.execute("SELECT `username` FROM `rfid` WHERE `card_id`=%(cardid)s", {'cardid': cardid_hex})
result = cursor.fetchone()
print result
shell.SendKeys(result['username'] + "{enter}")
while True:
try:
io = Serial('COM4', 9600, timeout=1)
while True:
try:
p = Packet(ISO14443A.Request)
reply = p.execute(io)
p = Packet(ISO14443A.Anticollision)
reply = p.execute(io)
cardid = reply.data
if cardid:
cardid_hex = "".join(map(lambda x: "%.2X" % x , cardid))
if cardid_hex != prevcardid:
prevcardid = cardid_hex
checkCard(cardid_hex)
else:
prevcardid = None
time.sleep(0.1)
except KeyboardInterrupt:
sys.exit()
except:
print sys.exc_info()[0]
break;
except:
pass