-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
NFC tags are popular with mobile phones, because they require no additional software to interact with. Just tap a tag with a phone (assuming you hit the right place on the phone, where the antenna is) and BOOM! A website opens! Convenient, seamless and ubiquitous.
PC-s don't have such software built in, but NFC4PC (aka nfc
) is a small unix-style utility for working with NFC tags. It reads URL-s from tags, transforms them if needed, and runs actions with those URL-s, by default opening a browser. Just like mobile phones do.
- Windows, macOS or Linux (tested on Windows 10 (64 bit), macOS 13.4 (M1), Debian Bookworm (amd64))
- a supported USB PC/SC contactless smart card reader
- Java 17+ with JavaFX (Zulu JDK recommended)
- Existing NFC tag with a URL (Type 2 like NXP NTAG-s or Type 4 like Fidesmo wearable with Fidesmo Links)
Download the JAR file from latest release.
Using from command line or in headless mode should work with any Java (17+). For desktop integration Java with JavaFX (like Zulu JDK) is required.
java -jar nfc4pc-230710.jar
Recommended to add an alias into your ~/.profile
:
echo 'alias nfc="JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home java -jar ~/Downloads/nfc4pc-230710.jar"' >> ~/.profile
Now the command to type on your terminal is simply "nfc
".
By default nfc
waits for a tap on any of the connected readers, reads the tag, prints the URL to standard output, and exits. Printing to standard output allows to integrate NFC interactions into other unix scripts.
If you don't tap a tag within 30 seconds, nfc
exits with exit code 2. The timeout can be changed with --timeout/-t
or disabled with --timeout 0
.
NFC is most useful with mobile phones. But if your mobile phone does not have NFC support, you can make the nfc
utility print a QR code instead, so that you could scan it with your phone. Just add --qrcode/-q
to the command line to always print a QR code with the URL to the terminal.
Generating QR codes in the terminal is so useful, that you can simply use nfc -q http://example.com
to print random QR codes with it.
During debugging and development it is sometimes needed not to just read a tag once, but to read multiple taps continuously. Use --continue/-c
to read multiple tags without exiting. Tags are read until the program is exited with Ctrl-C
.
When run interactively (versus daemon mode), nfc
usually prints the read URL to the terminal as a string or QR code. If you just want to launch the URL in a browser, use --browser/-b
. Your platforms default browser (URL handler) will be opened with the address from the scanned tag. On unix machines, if $BROWSER
is set, it is executed instead of the platform default browser, or you can specify a path to a browser (or, in fact, any executable) as argument to --browser
.
nfc --desktop
will run nfc4pc as a system tray / system menu item. NB! Java with JavaFX is required!
Normally, the URL that is read from the tag is the URL that is used (opened in browser or printed as a QR code). Sometimes it is useful to construct a new URL from the tag data. nfc
utility supports two type of automatic URL generation:
nfc --meta-url http://example.com/foobar
All tags (with or without URL) open at a different URL. A tag with original URL of http://example.org/sample
will open as http://example.com/foobar?uid=<hex>&url=https://example.org/sample
(properly URL-encoded, of course). URL is optional, tags without URL will open with just the UID parameter (so similar to --uid-url
)
nfc --uid-url http://example.com/foobar
All tags that don't have a URL payload will open with the UID embedded in a pre-defined URL instead, this case at http://example.com/foobar?uid=<hex>
. This is handy for making use of existing or locked NFC devices for automation purposes. Tags with a proper URL will still open with the original location (unlike with --meta-url
)
nfc --headless --webhook http://example.com/foobar
All tags will generate a type application/x-www-form-urlencoded
POST request to http://example.com/foobar
with values uid
and url
(optional)
Use --authorization <header>
to add Authorization header to the webhook POST. Values like Bearer XXXXXXXX
and Basic ZGVtbzpwQDU1dzByZA==
work (full authorization header)
You can also turn a supported smart card reader into a tag. Tapping the reader with your phone will open the emulated website address. Right now only ACS ACR 1252U reader with ACS PC/SC driver installed is supported. This will NOT work with Windows CCID driver or open source CCID driver present on Linux and macOS.
nfc --emulate https://example.com -qr # print the QR code of the emulated URL and emulate a Mifare Ultralight tag with the URL
-
Read a tag and print the URL on the terminal
nfc
-
Read a tag and open the default browser
nfc -b
-
Read a tag and print the QR code of it
nfc -q
-
Read tags continuously, printing the QR code of the tag after clearing the screen
nfc -c -q -C
-
Read a tag and open it on a development meta-url
nfc -m https://example.com/test -b
-
Read a tag and if it does not contain a URL, open in default browser a webpage with the UID as parameter
nfc -u https://example.com/test -b
Open a discussion or issue. Please include your operating system, reader, and tag information, if available (nfc --version --debug
)
There are many different apps and tools for desktops for working with NFC tags. Many of them are for pay, only available for Windows or tie you to a subscription, or are meant for NFC tag management. NFC4PC does not intend to become an all-encompassing NFC toolkit. If operating systems implemented the functionality of opening websites from NFC tags in a similar way as mobile phones do, this software would probably not exist. The goal of nfc
utility is to be as "invisible" as any other shell command - you would probably not pay for "ls" or "dir" commands, but the presence of them comes in handy. Likewise, the desktop integration has intentionally virtually no UI, as the goal of the tool is to be invisible, seamless, convenient and automagic.
Nevertheless, here's a list of software from the same field (TBD):
- aa
- bb
- cc