This Bash script uses curl to query ifconfig.me for your public IP address and then displays it in the Terminal on macOS.
Click to view script…
#!/bin/bash
# check_public_ip.command - Display your public IP address on macOS
# This script uses curl to query ifconfig.me, which returns your public IP address.
# Usage: ./check_public_ip.command
# Check if curl is installed
if ! command -v curl &>/dev/null; then
echo "Error: curl is not installed. Please install curl to use this script."
exit 1
fi
echo "Fetching public IP address..."
public_ip=$(curl -s ifconfig.me)
if [ -z "$public_ip" ]; then
echo "Error: Unable to retrieve public IP address."
exit 1
fi
echo "Your public IP address is: $public_ip"