Skip to content

Instantly share code, notes, and snippets.

@groundcat
Created July 8, 2023 21:22
Show Gist options
  • Save groundcat/e099c0b312d8a7e5b35deb9cdf8264a7 to your computer and use it in GitHub Desktop.
Save groundcat/e099c0b312d8a7e5b35deb9cdf8264a7 to your computer and use it in GitHub Desktop.
Checks connection and auto connect to Cloudflare Warp

Cloudflare Warp Status Check Script

This bash script checks the status of Cloudflare Warp for a given endpoint (https://cloudflare.com/cdn-cgi/trace). It uses curl to make a HTTP request to the specified URL, checks if the response contains "warp=on" or "warp=plus", and acts accordingly.

Prerequisites

Before running the script, make sure you have the following tools installed on your system:

  • curl: A command-line tool for making HTTP requests. You can install it with a package manager like apt, brew, or yum.
  • warp-cli: A command-line interface for managing Cloudflare Warp. Follow Cloudflare's instructions to install it.

Usage

  1. Download or clone this repository.

  2. Navigate to the directory containing the script.

  3. Make the script executable with the following command:

    chmod +x warp_status_check.sh
    
  4. Run the script:

    ./warp_status_check.sh
    
  5. The script will make a request to the Cloudflare endpoint, check the response, and output one of the following messages:

    • Status: warp=on
    • Status: warp=plus
    • Not using Cloudflare Warp

    If the last message is output, the script will also execute warp-cli connect to try to connect to Cloudflare Warp.

License

This project is licensed under the MIT License - see the LICENSE file for details.

#!/bin/bash
# Call the URL and save the output
response=$(curl -s https://cloudflare.com/cdn-cgi/trace)
# Check for "warp=on" or "warp=plus" in the response
if [[ $response == *"warp=on"* ]]; then
echo "Status: warp=on"
elif [[ $response == *"warp=plus"* ]]; then
echo "Status: warp=plus"
else
echo "Not using Cloudflare Warp"
# If warp=on or warp=plus not found, execute "warp-cli connect"
warp-cli connect
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment