Just do a litle trial,
Trying to read a magnetic stripe card using Chinese MSRE 647 magnetic reader.
This reader is use a usb serial port, so check the usb
$lsusb
returning :
..
Bus 004 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
and then look for ttyUSB port used for this device using dmesg command :
...
[111382.037104] pl2303 4-1:1.0: pl2303 converter detected
[111382.049128] usb 4-1: pl2303 converter now attached to ttyUSB0
now lets coding :
#!/usr/bin/env python
import os
import time
import serial
if os.getuid()!=0:
print "[-] This script requiring root privilege"
exit(1)
#setup serial connection
ser=serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0
)
#Check the port
if not ser.isOpen():
ser.open()
#initialize reader
print "[+] Initiating .."
ser.write("\x1b\x3f\x56")
time.sleep(0.1)
#open connection
print "[+] Open reader connection "
ser.write("\x1b\x31")
time.sleep(0.1)
#read 3 track of card timeout 3 second
print "[+] Swipe card in 3 second"
ser.write("\x1b\x42\x74")
time.sleep(5)
val=""
while ser.inWaiting()>0:
val += ser.read(1)
#close connection
print "[+] closing connection .."
ser.write("\x1b\x30")
time.sleep(0.1)
# tutup port
ser.close()
# show the card value
print "[+] Card values :\n" + repr(val)
Run the script using root privilege or use sudo,
That for the first step.... next i will try writing to the card or more....
( i think it will be interesting when it connected to arduino ...)
No comments:
Post a Comment