Last active
January 16, 2024 15:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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