#!/usr/bin/env bash # ============================================================================== # YesBut.monster — VPS Exit & Node Self-Check (vless.yesbut.monster) # Honest diagnostic script for checking: # 1. Outbound access from your VPS (AI, Streaming, Global Web, Geo-blocks) # 2. Encrypted DNS (DoH) availability & system DNS spoofing detection # 3. Real Telegram DC reachability via MTProto obfuscated2 handshake # 4. Local Xray / port 443 readiness (if running on a VPN node) # # Read before running: https://vless.yesbut.monster/selfcheck.sh # Zero silent package installs. Read-only network checks only. # ============================================================================== set -u TIMEOUT=5 IP_VERSION=4 PROXY="" CHECK_DNS=true CHECK_TG=true JSON_OUTPUT=false RED="\033[31m" YELLOW="\033[33m" CYAN="\033[36m" GREEN="\033[32m" BLUE="\033[34m" DIM="\033[2;90m" BOLD="\033[1m" RESET="\033[0m" TARGETS=( "chatgpt.com|AI (OpenAI)" "claude.ai|AI (Anthropic)" "gemini.google.com|AI (Google)" "netflix.com|Streaming" "spotify.com|Streaming" "youtube.com|Video" "redirector.googlevideo.com/report_mapping?di=no|YouTube CDN" "instagram.com|Social" "x.com|Social" "discord.com|Chat / Voice" "api.telegram.org|Telegram API" "github.com|Dev / Releases" ) TELEGRAM_DCS=( "DC1|149.154.175.50" "DC2|149.154.167.51" "DC3|149.154.175.100" "DC4|149.154.167.91" "DC5|149.154.171.5" ) usage() { cat <&2 exit 2 fi ;; -6|--ipv6) IP_VERSION=6 shift ;; -p|--proxy) if [[ -n "${2:-}" ]]; then PROXY="$2" shift 2 else echo "Empty --proxy value" >&2 exit 2 fi ;; --no-dns) CHECK_DNS=false shift ;; --no-tg) CHECK_TG=false shift ;; -j|--json) JSON_OUTPUT=true shift ;; *) echo "Unknown option: $1" >&2 usage >&2 exit 2 ;; esac done if ! command -v curl >/dev/null 2>&1; then echo "Error: 'curl' is required. Please install curl manually and re-run." >&2 exit 1 fi CURL_USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" build_curl_base() { local -n _arr=$1 _arr=( -sS --compressed -L --max-redirs 3 -"$IP_VERSION" --connect-timeout "$TIMEOUT" --max-time "$((TIMEOUT + 3))" -A "$CURL_USER_AGENT" -H "Accept-Language: en-US,en;q=0.9" ) if [[ -n "$PROXY" ]]; then if [[ "$PROXY" == *"://"* ]]; then _arr+=(--proxy "$PROXY") else _arr+=(--proxy "socks5h://$PROXY") fi fi } json_escape() { local s="${1//\\/\\\\}" s="${s//\"/\\\"}" s="${s//$'\n'/ }" s="${s//$'\r'/}" printf '%s' "$s" } detect_egress_info() { local base=() build_curl_base base local ipinfo_raw="" ipinfo_raw=$(curl "${base[@]}" --max-time 4 "https://ipinfo.io/json" 2>/dev/null || true) EGRESS_IP="" EGRESS_ORG="" EGRESS_COUNTRY="" if [[ -n "$ipinfo_raw" ]]; then EGRESS_IP=$(printf '%s' "$ipinfo_raw" | sed -n 's/.*"ip"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1) EGRESS_ORG=$(printf '%s' "$ipinfo_raw" | sed -n 's/.*"org"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1) EGRESS_COUNTRY=$(printf '%s' "$ipinfo_raw" | sed -n 's/.*"country"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1) fi if [[ -z "$EGRESS_IP" ]]; then EGRESS_IP=$(curl "${base[@]}" --max-time 4 "https://api.ipify.org" 2>/dev/null || true) fi } probe_target() { local target="$1" local category="$2" local base=() build_curl_base base local tmp_body tmp_body=$(mktemp) local meta="" local attempt for attempt in 1 2; do meta=$(curl "${base[@]}" -o "$tmp_body" -w "%{http_code}|%{time_total}|%{size_download}" "https://$target" 2>/dev/null || true) meta=$(printf '%s\n' "$meta" | tail -n1) if [[ "${meta%%|*}" != "000" && -n "$meta" ]]; then break fi done [[ -z "$meta" ]] && meta="000|0|0" local http_code time_total size_dl IFS='|' read -r http_code time_total size_dl <<<"$meta" [[ -z "$http_code" ]] && http_code="000" local body_sample body_sample=$(head -c 16384 "$tmp_body" 2>/dev/null | tr '\0' ' ') rm -f "$tmp_body" local status="ERR" local detail="HTTP $http_code" local lower_body lower_body=$(printf '%s' "$body_sample" | tr '[:upper:]' '[:lower:]') if [[ "$http_code" == "000" ]]; then status="BLOCKED" detail="TIMEOUT / TCP DROP" elif [[ "$http_code" == "451" ]]; then status="GEO" detail="GEO / LEGAL (451)" elif printf '%s' "$lower_body" | grep -qE "unsupported_country|not available in your country|not available in your region|restricted in your country|access denied due to location|sorry, you have been blocked"; then status="GEO" detail="GEO-BLOCK (HTTP $http_code)" elif [[ "$http_code" == "403" ]] && printf '%s' "$lower_body" | grep -qE "just a moment|enable javascript and cookies|cf-mitigated|attention required"; then status="WAF" detail="CF / JS CHALLENGE (403)" elif [[ "$http_code" == "403" ]]; then status="DENIED" detail="ACCESS DENIED (403)" elif [[ "$http_code" =~ ^2[0-9][0-9]$ ]]; then status="OK" detail="HTTP $http_code" elif [[ "$http_code" =~ ^3[0-9][0-9]$ ]]; then status="OK" detail="REDIRECT ($http_code)" else status="WARN" detail="HTTP $http_code" fi local ms="0" if [[ -n "$time_total" ]]; then ms=$(awk -v t="$time_total" 'BEGIN { printf "%.0f", t * 1000 }' 2>/dev/null || echo "0") fi printf '%s|%s|%s|%s|%s|%s\n' "$target" "$category" "$status" "$detail" "$ms" "$http_code" } query_doh_ips() { local domain="$1" local base=() build_curl_base base local resp resp=$(curl "${base[@]}" -H "Accept: application/dns-json" "https://cloudflare-dns.com/dns-query?name=$domain&type=A" 2>/dev/null || true) printf '%s' "$resp" | grep -oE '"data":"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"' | sed 's/"data":"//;s/"//' | sort -u } query_system_ips() { local domain="$1" if command -v getent >/dev/null 2>&1; then getent ahostsv4 "$domain" 2>/dev/null | awk '{print $1}' | sort -u elif command -v dig >/dev/null 2>&1; then dig +short "$domain" A 2>/dev/null | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | sort -u fi } run_dns_checks() { DOH_STATUS="UNAVAILABLE" DNS_SPOOF_STATUS="SKIPPED" DNS_DETAIL="" local doh_cf_ips doh_cf_ips=$(query_doh_ips "rutracker.org") if [[ -n "$doh_cf_ips" ]]; then DOH_STATUS="OK" else DOH_STATUS="BLOCKED" fi if [[ -n "$PROXY" ]]; then DNS_SPOOF_STATUS="SKIPPED_PROXY" DNS_DETAIL="System DNS check skipped when --proxy is active" return fi if [[ "$DOH_STATUS" != "OK" ]]; then DNS_SPOOF_STATUS="UNVERIFIED" DNS_DETAIL="Cloudflare DoH unreachable to compare against system DNS" return fi local sys_ips sys_ips=$(query_system_ips "rutracker.org") if [[ -z "$sys_ips" ]]; then DNS_SPOOF_STATUS="NO_RESPONSE" DNS_DETAIL="System DNS failed to resolve rutracker.org while DoH succeeded" return fi if printf '%s\n' "$sys_ips" | grep -qE '^(127\.|0\.0\.0\.0|10\.|192\.168\.)'; then DNS_SPOOF_STATUS="SPOOFED" DNS_DETAIL="System DNS returned local/stub IP ($(echo "$sys_ips" | tr '\n' ' '))" return fi local common common=$(comm -12 <(printf '%s\n' "$doh_cf_ips") <(printf '%s\n' "$sys_ips") 2>/dev/null || true) if [[ -n "$common" ]]; then DNS_SPOOF_STATUS="CLEAN" DNS_DETAIL="System DNS matches DoH (1.1.1.1)" else DNS_SPOOF_STATUS="DIFF" DNS_DETAIL="System DNS ($(echo "$sys_ips" | tr '\n' ' ')) differs from DoH ($(echo "$doh_cf_ips" | tr '\n' ' '))" fi } # Portable obfuscated2 MTProto handshake for bash + openssl mtproto_probe_dc() { local ip="$1" local dc_id="$2" if ! command -v openssl >/dev/null 2>&1 || ! command -v od >/dev/null 2>&1; then return 2 fi local header="" while true; do header=$(head -c 64 /dev/urandom | od -An -v -tx1 | tr -d ' \n') [[ ${#header} -eq 128 ]] || return 2 case "${header:0:8}" in ef*|48454144|504f5354|47455420|4f505449|dddddddd|eeeeeeee|16030102) continue ;; esac [[ "${header:8:8}" == "00000000" ]] && continue break done local dc_hex dc_hex=$(printf "%02x00" "$dc_id") header="${header:0:112}eeeeeeee${dc_hex}${header:124:4}" local nonce nonce=$(head -c 16 /dev/urandom | od -An -v -tx1 | tr -d ' \n') local ts ts_le ts=$(date +%s) ts_le=$(printf "%02x%02x%02x%02x" $((ts & 255)) $((ts >> 8 & 255)) $((ts >> 16 & 255)) $((ts >> 24 & 255))) # frame len + auth_key_id(0) + msg_id + msg_len(20) + req_pq_multi(f18e7ebe) + nonce local request="28000000000000000000000000000000${ts_le}14000000f18e7ebe${nonce}" local key="${header:16:64}" local iv="${header:80:32}" local rev="" local i for (( i=94; i>=0; i-=2 )); do rev+="${header:16+i:2}" done local dkey="${rev:0:64}" local div="${rev:64:32}" local sealed sealed=$(printf '%b' "$(printf '%s' "${header}${request}" | sed 's/../\\x&/g')" | openssl enc -aes-256-ctr -K "$key" -iv "$iv" -nosalt 2>/dev/null | od -An -v -tx1 | tr -d ' \n') [[ ${#sealed} -ge 208 ]] || return 1 local payload="${header:0:112}${sealed:112}" local reply="" reply=$(timeout "$TIMEOUT" bash -c ' exec 3<>"/dev/tcp/$1/$2" || exit 1 printf "%b" "$(printf "%s" "$3" | sed "s/../\\\\x&/g")" >&3 head -c 44 <&3 | od -An -v -tx1 | tr -d " \n" ' _ "$ip" "443" "$payload" 2>/dev/null || true) [[ ${#reply} -eq 88 ]] || return 1 local plain plain=$(printf '%b' "$(printf '%s' "$reply" | sed 's/../\\x&/g')" | openssl enc -aes-256-ctr -K "$dkey" -iv "$div" -nosalt 2>/dev/null | od -An -v -tx1 | tr -d ' \n') [[ "${plain:48:8}" == "63241605" && "${plain:56:32}" == "$nonce" ]] } check_local_node() { LOCAL_XRAY="not_installed" LOCAL_PORT_443="closed" LOCAL_OTHER_PORTS="" if command -v systemctl >/dev/null 2>&1; then if systemctl list-unit-files xray.service >/dev/null 2>&1; then LOCAL_XRAY=$(systemctl is-active xray 2>/dev/null || echo "inactive") fi fi if command -v ss >/dev/null 2>&1; then if ss -tln 2>/dev/null | grep -qE '(:|\])443\b'; then LOCAL_PORT_443="listening" fi if [[ "$(id -u)" -eq 0 ]]; then LOCAL_OTHER_PORTS=$(ss -tlpn 2>/dev/null | awk '/xray/ && $4 !~ /^(127\.0\.0\.1|\[::1\]):/ {print $4}' | awk -F: '{print $NF}' | grep -v '^443$' | sort -u | tr '\n' ',' | sed 's/,$//') fi fi } main() { detect_egress_info local tmpdir tmpdir=$(mktemp -d) local pids=() local i=0 for item in "${TARGETS[@]}"; do local t="${item%%|*}" local c="${item##*|}" probe_target "$t" "$c" >"$tmpdir/web_$i.txt" & pids+=($!) ((i++)) if (( i % 4 == 0 )); then for pid in "${pids[@]}"; do wait "$pid" 2>/dev/null || true done pids=() fi done if $CHECK_TG && [[ -z "$PROXY" ]]; then local j=0 for item in "${TELEGRAM_DCS[@]}"; do local dc="${item%%|*}" local ip="${item##*|}" ( if mtproto_probe_dc "$ip" "${dc#DC}"; then echo "$dc|$ip|OK" else rc=$? if [[ $rc -eq 2 ]]; then echo "$dc|$ip|SKIP" else echo "$dc|$ip|BLOCKED" fi fi ) >"$tmpdir/tg_$j.txt" & pids+=($!) ((j++)) done fi if $CHECK_DNS; then run_dns_checks else DOH_STATUS="SKIPPED" DNS_SPOOF_STATUS="SKIPPED" DNS_DETAIL="Skipped by --no-dns" fi check_local_node for pid in "${pids[@]}"; do wait "$pid" 2>/dev/null || true done local web_results=() for (( k=0; k<${#TARGETS[@]}; k++ )); do if [[ -f "$tmpdir/web_$k.txt" ]]; then web_results+=("$(cat "$tmpdir/web_$k.txt")") fi done local tg_results=() if $CHECK_TG && [[ -z "$PROXY" ]]; then for (( k=0; k<${#TELEGRAM_DCS[@]}; k++ )); do if [[ -f "$tmpdir/tg_$k.txt" ]]; then tg_results+=("$(cat "$tmpdir/tg_$k.txt")") fi done fi rm -rf "$tmpdir" if $JSON_OUTPUT; then printf '{\n' printf ' "egress": {"ip": "%s", "org": "%s", "country": "%s"},\n' \ "$(json_escape "$EGRESS_IP")" "$(json_escape "$EGRESS_ORG")" "$(json_escape "$EGRESS_COUNTRY")" printf ' "dns": {"doh": "%s", "spoofing": "%s", "detail": "%s"},\n' \ "$(json_escape "$DOH_STATUS")" "$(json_escape "$DNS_SPOOF_STATUS")" "$(json_escape "$DNS_DETAIL")" printf ' "local_node": {"xray": "%s", "port_443": "%s", "other_xray_ports": "%s"},\n' \ "$(json_escape "$LOCAL_XRAY")" "$(json_escape "$LOCAL_PORT_443")" "$(json_escape "$LOCAL_OTHER_PORTS")" printf ' "web": [\n' local idx=0 for row in "${web_results[@]}"; do IFS='|' read -r tgt cat st det ms code <<<"$row" local comma="," (( idx == ${#web_results[@]} - 1 )) && comma="" printf ' {"target": "%s", "category": "%s", "status": "%s", "detail": "%s", "ms": %s, "http_code": "%s"}%s\n' \ "$(json_escape "$tgt")" "$(json_escape "$cat")" "$(json_escape "$st")" "$(json_escape "$det")" "${ms:-0}" "$(json_escape "$code")" "$comma" ((idx++)) done printf ' ],\n' printf ' "telegram_mtproto": [\n' idx=0 for row in "${tg_results[@]}"; do IFS='|' read -r dc ip st <<<"$row" local comma="," (( idx == ${#tg_results[@]} - 1 )) && comma="" printf ' {"dc": "%s", "ip": "%s", "status": "%s"}%s\n' \ "$(json_escape "$dc")" "$(json_escape "$ip")" "$(json_escape "$st")" "$comma" ((idx++)) done printf ' ]\n}\n' exit 0 fi echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}" echo -e " ${BOLD}${BLUE}YesBut.monster${RESET} ${DIM}·${RESET} ${BOLD}VPS Exit & Node Self-Check${RESET}" echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}" echo -e " ${DIM}Egress:${RESET} ${CYAN}${EGRESS_IP:-unknown}${RESET} | ${EGRESS_ORG:-unknown org} ${EGRESS_COUNTRY:+[$EGRESS_COUNTRY]}" [[ -n "$PROXY" ]] && echo -e " ${DIM}Proxy:${RESET} $PROXY" echo -e "${CYAN}──────────────────────────────────────────────────────────────────────${RESET}" printf " %-38s %-14s %-22s %s\n" "Service" "Category" "Result" "RTT" echo -e "${DIM}----------------------------------------------------------------------${RESET}" local cnt_ok=0 cnt_geo=0 cnt_waf=0 cnt_blk=0 for row in "${web_results[@]}"; do IFS='|' read -r tgt cat st det ms _code <<<"$row" local short_tgt="$tgt" (( ${#short_tgt} > 36 )) && short_tgt="${short_tgt:0:33}..." local color="$YELLOW" case "$st" in OK) color="$GREEN"; ((cnt_ok++)) ;; GEO) color="$RED"; ((cnt_geo++)) ;; WAF|DENIED) color="$YELLOW"; ((cnt_waf++)) ;; BLOCKED) color="$RED"; ((cnt_blk++)) ;; esac printf " %-38s %-14s ${color}%-22s${RESET} %4sms\n" "$short_tgt" "$cat" "$det" "$ms" done echo -e "${DIM}----------------------------------------------------------------------${RESET}" echo -e " ${BOLD}Summary:${RESET} ${GREEN}OK:$cnt_ok${RESET} | ${YELLOW}CF/WAF/403:$cnt_waf${RESET} | ${RED}GEO:$cnt_geo${RESET} | ${RED}DROP/TIMEOUT:$cnt_blk${RESET}" echo if $CHECK_DNS; then local dns_c="$YELLOW" [[ "$DNS_SPOOF_STATUS" == "CLEAN" ]] && dns_c="$GREEN" [[ "$DNS_SPOOF_STATUS" == "SPOOFED" ]] && dns_c="$RED" echo -e " ${BOLD}DNS Check:${RESET} DoH=${CYAN}${DOH_STATUS}${RESET} | System=${dns_c}${DNS_SPOOF_STATUS}${RESET} ${DIM}(${DNS_DETAIL})${RESET}" fi if $CHECK_TG; then if [[ -n "$PROXY" ]]; then echo -e " ${BOLD}Telegram MTProto:${RESET} ${DIM}skipped (--proxy mode)${RESET}" else local tg_line="" for row in "${tg_results[@]}"; do IFS='|' read -r dc _ip st <<<"$row" if [[ "$st" == "OK" ]]; then tg_line+="${GREEN}${dc}:OK${RESET} " elif [[ "$st" == "SKIP" ]]; then tg_line+="${DIM}${dc}:SKIP${RESET} " else tg_line+="${RED}${dc}:FAIL${RESET} " fi done echo -e " ${BOLD}Telegram MTProto:${RESET} $tg_line" fi fi echo -e " ${BOLD}Local Node:${RESET} xray=${CYAN}${LOCAL_XRAY}${RESET} | 443/tcp=${CYAN}${LOCAL_PORT_443}${RESET}${LOCAL_OTHER_PORTS:+ | ${YELLOW}extra xray ports: $LOCAL_OTHER_PORTS${RESET}}" echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}" } main