We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Writing python scripts for the RFID/NFC expansion



  • Hello all, I got the RFID/NFC expansion and I want to write a script that will tell the reader to continuously read any cards it comes into contact with then store those in a file. I know how to get the reader to read by entering:
    nfc-list
    Which it does, then it exits. So how would I script it in a python file to keep reading and store everything into a file? I know how to code in python fairly well, although it's been a bit since I've done any serious coding, but I know how to read from and write to a file. It's getting it to interact with the RFID/NFC expansion I'm not sure about.



  • @William-Srite
    basically what i'm asking is how to control the rfid/nfc exp from inside a progra...any program: python node.js, etc. the documentation shows how to control it via the command line but doesn't explain how to use it with a script. If I need to import a library or anything.
    I've tried based on some I've found online, like this one, but it doesn't show me what I need to know. Like, how do I keep it in read mode in a loop and then write the results to a file or even an array.
    https://github.com/OnionIoT/RFID-Access-Control/blob/master/rfid-access-control.py

    I'm a security researcher and need to build a handheld, barry powered device to scan a client's employees badges to do an audit. So, I have the RFID exp and the battery powered dock with LiPo battery, but I'm having trouble writing the script.



  • OK, I figured it out. Here's a test script I wrote real quick to have a proof of concept:

    import os
    scan = os.system("nfc-list")
    def scanFunc():
    while 1:
    scan
    return scan
    print(scanFunc())

    And the output:

    nfc-list uses libnfc v0.2.2
    NFC device: Omega NFC Expansion opened
    1 ISO14443A passive target(s) found:
    ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00 44
    UID (NFCID1): 04 1e bb 32 ed 4c 80
    SAK (SEL_RES): 00

    So, after you have this, you can just output it to a text file or JSON file by:

    import string
    outfile = open("result.txt", "w")

    outfile.write(scan)



  • @William-Srite

    I'm just starting with the expansion and also finding it frustrating to use. But I had some comments on your thread and thought I'd share what I've figured out in the two days I've been messing with it.

    I'm a security researcher and need to build a handheld, barry powered device to scan a client's employees badges to do an audit.

    Me too! Specifically I do penetration testing of all sorts. I would think you'd want something with a bit more range for an engagement?

    basically what i'm asking is how to control the rfid/nfc exp from inside a progra...any program: python node.js, etc.

    First, you should forget there are any "tools" installed on the Omega for use with the expansion. And while the documentation is frustrating, it does tell us some useful information that would have taken us a few minutes to figure out or if you are me quite a few minutes to figure out:

    The Expansion is based on the popular PN532 NFC Chip and communicates with the Omega via UART1.
    
    • PN532 chip
    • talks via UART1
    # nfc-scan-device
    nfc-scan-device uses libnfc reboot-3483-gd1bcad0
    1 NFC device(s) found:
    - pn532_uart:/dev/ttyS1:
        pn532_uart:/dev/ttyS1
    
    • device is on /dev/ttyS1
    error   libnfc.driver.pn532_uart        Serial port already claimed: /dev/ttyS1
    nfc-mfultralight: ERROR: Error opening NFC device
    
    • their "tools" are using the libnfc driver

    Ok so to get back answering your question, to control the expansion from inside a program you have two choices:

    1. Find a library in the language of your choice that uses the libnfc driver and tell it to talk to a pn532 chip on /dev/ttyS1.
    2. Find a library in the language of your choice that can talk to the pn532 on /dev/ttyS1 directly.

    OK, I figured it out. Here's a test script I wrote real quick to have a proof of concept:

    import os
    scan = os.system("nfc-list")
    def scanFunc():
    while 1:
    scan
    return scan 
    print(scanFunc())
    
    import string
    outfile = open("result.txt", "w")
    
    outfile.write(scan)
    

    Even ignoring the issues with the code I probably wouldn't want to use this in any real-world scenario. Did you by chance come up with something else? And honestly for something like what you are trying to do here you could just write a shell script and save yourself the overhead of the python interpreter.

    However, if you do want to write something in python, find a library that lets you use one of the above two methods I mentioned and I think you'll be much happier with the expansion. I know I was.


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.