Skip to content

Instantly share code, notes, and snippets.

@sysbitnet
Last active February 27, 2024 14:24
Show Gist options
  • Save sysbitnet/3e50a007d8083c01a73d2bee23ffd570 to your computer and use it in GitHub Desktop.
Save sysbitnet/3e50a007d8083c01a73d2bee23ffd570 to your computer and use it in GitHub Desktop.
Get Public IP # Create a simple script to fetch your public IP address using the dig command. If you're using a Unix-like system (Linux or macOS), you can create a bash script.
#!/bin/bash
# Fetch public IP address using dig and OpenDNS resolver
ip_address=$(dig +short myip.opendns.com @resolver1.opendns.com)
# Print the public IP address
echo "Your public IP address is: $ip_address"
# Save this script in a file, for example, get_public_ip.sh. Make it executable using the following command: chmod +x get_public_ip.sh
# Run the script by executing: ./get_public_ip.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment