Skip to content

Instantly share code, notes, and snippets.

@simonesestito
Last active August 12, 2024 15:20
Show Gist options
  • Save simonesestito/aa7bd9a498d135b1f9a16fa839b6d26d to your computer and use it in GitHub Desktop.
Save simonesestito/aa7bd9a498d135b1f9a16fa839b6d26d to your computer and use it in GitHub Desktop.
Simple script to send a file in LAN via HTTP
#!/bin/bash --
set -euo pipefail
PORT=8000
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file_to_send>"
exit 1
fi
# Extract only the filename
file_to_send=$(basename "$1")
# Create a temporary directory
tmpdir=$(mktemp -d)
# Clean up the temporary directory on exit
trap 'rm -rf "$tmpdir"' EXIT
# Copy the files to the temporary directory
cp "$1" "$tmpdir"
# Show the QR with the URL
my_lan_ip=$(ip a | grep inet | grep wlan | grep -Eo 'inet [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | cut -d' ' -f2)
echo "http://$my_lan_ip:$PORT/$file_to_send" | qrencode -o - -t UTF8
# Make a Python server in that directory
python3 -m http.server -d "$tmpdir" -b "$my_lan_ip" $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment