diff --git a/README.md b/README.md index 4fb8a97..9032946 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,14 @@ - [`pdfcompress`](./bin/pdfcompress) - A utility that uses convert to render each page of a PDF to a JPEG image with adjustable quality and then merges them back into a single document. + A utility that uses convert to render each page of a PDF to a JPEG image with adjustable quality and then merges them back into a single document. + + With the verbose option this will also print processing information and the estimated remaining time. + +- [`hash2addr`](./bin/hash2addr) + + Outputs a randomly generated IP address and port number based on the MD5 hash of the input string. - With the verbose option this will also print processing information and the estimated remaining time. ## Install diff --git a/bin/hash2addr b/bin/hash2addr new file mode 100755 index 0000000..2d1ea1a --- /dev/null +++ b/bin/hash2addr @@ -0,0 +1,28 @@ +#!/bin/bash + +# Display help message +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + echo "Usage: $(basename $0) " + echo "Outputs a randomly generated IP address and port number based on the MD5 hash of the input string." + exit 0 +fi + +# Check that input string is provided +if [ -z "$1" ]; then + echo "Error: input string not provided." + echo "Usage: $(basename $0) " + exit 1 +fi + +input_str="$1" + +# Hash the input string using MD5 and extract the first 4 bytes +hash_bytes="$(echo -n $input_str | md5sum | cut -d' ' -f1 | head -c 8)" + +# Create an IP address in the 127.0.0.0/8 range using the first 3 bytes of the hash +ip="127.$(printf '%d.%d.%d' 0x${hash_bytes:0:2} 0x${hash_bytes:2:2} 0x${hash_bytes:4:2})" + +# Use the last 2 bytes of the hash to generate a port number in the range 1024-65535 +port="$((0x${hash_bytes:6:2} % (65535 - 1024) + 1024))" + +echo "$ip:$port"