#!/bin/sh # FYI - This client half of a very basic UDP protocol, For Your Information, implements Let Me Know. # Written in 2025 by Prince Trippy . # To the extent possible under law, the author(s) have dedicated all copyright # and related and neighboring rights to this software to the public domain worldwide. # This software is distributed without any warranty. # You should have received a copy of the CC0 Public Domain Dedication along with this software. # If not, see . # This program takes the tag to check, followed by server name, optional port, and optional timeout. # I hate writing sh programs, and I hate learning how to write better, more complicated sh programs. # In order to avoid most of the name dumbfuckery of sh, I keep most everything in the dumb pipeline. # I recommend reading my comments in the similar, even simpler sh program I wrote in 2022, named tp. # Use of diff appeared to be the simplest means for me to compare the tag sent back with that given. # Of course, that means I must play with mktemp, which means I must establish a handler to clean up. # I can only expect this program to run so quickly that the file won't touch the storage in any way. # Use of timeout is suboptimal, but only OpenBSD netcat has the -W switch to limit it to one packet. # The program is intended to be used by cron moreso than interactively, so this is not a great loss. # Ideally, the program checks its response's origin matches, but netcat lacks an interface for such. set -e file=$(mktemp --quiet --tmpdir) trap 'rm "$file"' EXIT env printf '%s\c' "${1:?Provide a tag.}" > "$file" env printf '%s\c' "$1" | timeout "${4:-1s}" netcat -u "${2:?Provide an address.}" "${3:-411}" 2>/dev/null | diff --brief - "$file" >/dev/null 2>/dev/null .