Skip to content

Instantly share code, notes, and snippets.

@ahbanavi
Last active January 16, 2024 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahbanavi/9e10eeb67fd9f5c581f57ca30637b052 to your computer and use it in GitHub Desktop.
Save ahbanavi/9e10eeb67fd9f5c581f57ca30637b052 to your computer and use it in GitHub Desktop.
This Bash script replaces hostnames with IP addresses in V2Ray and VLESS server configurations (from subscription url) by resolving each domain to its IP.
#!/bin/bash
# read url from args
url=$1
# If no URL is provided, exit with usage
if [[ -z "$url" ]]; then
echo "Usage: $0 <url>"
exit 1
fi
# Fetch the content from the URL
content=$(curl -s "$url")
# Process each line of the content
echo "$content" | while read -r line; do
# Extract the first URL from each line using regex
first_url=$(echo "$line" | grep -oP '(?<=@)[^:]+' | head -n 1)
# If a URL is found, resolve it to an IP address
if [[ ! -z "$first_url" ]]; then
ip=$(dig +short "$first_url" | head -n 1)
# Replace the URL with the IP address in the line
new_line=$(echo "$line" | sed "s|$first_url|$ip|")
echo "$new_line"
else
echo "$line"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment