├── readme.md └── pingtunnel.sh /readme.md: -------------------------------------------------------------------------------- 1 | # PingTunnel - اسکریپت مدیریت تانل ICMP 2 | 3 | ![PingTunnel Logo](https://img.shields.io/badge/PingTunnel-v1.0-brightgreen)\ 4 | اسکریپت `pingtunnel` یه ابزار ساده و متوسط برای راه‌اندازی و مدیریت تانل ‌های ICMP با استفاده از پروژه‌ی PingTunnel است. این اسکریپت برای ایجاد ارتباط بین سرورهای ایران و خارج طراحی شده و از systemd برای مدیریت سرویس‌ ها استفاده میکنه. 5 | 6 | ## ویژگی‌ها 7 | 8 | - **اجرای مستقیم**: اسکریپت رو با یه دستور ساده می‌تونید اجرا کنید. 9 | - **نصب خودکار**: هسته‌ی PingTunnel به‌صورت خودکار موقع اجرای اسکریپت نصب میشه. 10 | - **پشتیبانی از معماری‌های مختلف**: سازگار با معماری‌های متنوع CPU مثل x86_64، ARM، AArch64، MIPS و غیره. 11 | - **مدیریت آسان**: منوی رنگی و کاربرپسند برای پیکربندی، مدیریت، و بررسی وضعیت تانل‌ ها. 12 | - **پیکربندی سرورهای ایران و خارج**: پشتیبانی از تنظیمات کلاینت (ایران) و سرور (خارج). 13 | - **مدیریت سرویس‌ها**: امکان ری‌ استارت، توقف، حذف، مشاهده لاگ‌ها و وضعیت سرویس‌ ها. 14 | 15 | ## پیش‌نیازها 16 | 17 | - **سیستم‌عامل**: توزیع لینوکس (تست‌شده روی اوبونتو،). 18 | - **دسترسی روت**: اسکریپت باید با دسترسی روت اجرا بشه. 19 | - **ابزارهای مورد نیاز**: 20 | - `curl` برای دانلود فایل‌ها. 21 | - `unzip` برای استخراج فایل‌های فشرده. 22 | - `systemd` برای مدیریت سرویس‌ها. 23 | - `jq` برای نمایش اطلاعات سرور (اختیاری). 24 | 25 | ## نصب و راه‌اندازی 26 | 27 | ### اجرای مستقیم 28 | 29 | برای اجرای سریع اسکریپت، از دستور زیر استفاده کنید: 30 | 31 | ```bash 32 | bash <(curl -Ls https://raw.githubusercontent.com/ppouria/ping-tunnel/main/pingtunnel.sh) 33 | ``` 34 | 35 | - این دستور اسکریپت رو دانلود و اجرا میکنه. 36 | - هسته‌ی PingTunnel به‌صورت خودکار نصب میشه و منوی اصلی نمایش داده میشه. 37 | 38 | ### نصب دستی 39 | 40 | 1. ریپازیتوری رو کلون کنید: 41 | 42 | ```bash 43 | git clone https://github.com/ppouria/ping-tunnel.git 44 | cd ping-tunnel 45 | ``` 46 | 47 | 2. دسترسی اجرایی بدید: 48 | 49 | ```bash 50 | chmod +x pingtunnel.sh 51 | ``` 52 | 53 | 3. اسکریپت رو اجرا کنید: 54 | 55 | ```bash 56 | sudo ./pingtunnel.sh 57 | ``` 58 | 59 | ## نحوه‌ی استفاده 60 | 61 | ### پیکربندی سرور ایران (کلاینت) 62 | 63 | 1. گزینه‌ی 1 و سپس "Configure for Iran server" رو انتخاب کنید. 64 | 2. آدرس IP سرور خارج رو وارد کنید. 65 | 3. یه پورت معتبر (1025 تا 65535) انتخاب کنید، این پورت، باید پورت اینباند xray باشه. 66 | 4. سرویس systemd برای تانل ایجاد و فعال میشه. 67 | 68 | ### پیکربندی سرور خارج (سرور) 69 | 70 | 1. گزینه‌ی 1 و سپس "Configure for Kharej server" رو انتخاب کنید. 71 | 2. سرویس systemd برای سرور ایجاد و فعال میشه. 72 | 73 | ## نکات مهم 74 | 75 | - **اتصال اینترنت**: قبل از اجرا، مطمئن بشید به اینترنت متصل هستید. 76 | - **پورت‌ ها**: پورت انتخاب‌شده باید آزاد و توسط فایروال بلاک نشده باشه. 77 | - **ICMP**: اسکریپت تنظیمات ICMP رو به‌ صورت خودکار اعمال میکنه. 78 | - **حذف هسته**: قبل از حذف هسته، همه‌ی سرویس‌ها رو از منوی مدیریت حذف کنید. 79 | - **پشتیبانی توزیع‌ ها**: اسکریپت برای اوبونتو بهینه شده. برای توزیع‌ های دیگه، ممکنه نیاز به نصب دستی وابستگی‌ ها باشه. 80 | 81 | ## عیب‌یابی 82 | 83 | - **خطای معماری**: مطمئن بشید معماری CPU شما پشتیبانی میشه. 84 | - **خطای پورت**: با `ss -tln` پورت‌های اشغال‌شده رو چک کنید. 85 | - **مشکلات سرویس**: از گزینه‌ی "View service logs" برای دیدن لاگ‌ها استفاده کنید. 86 | 87 | ## مشارکت 88 | 89 | اگه پیشنهادی برای بهبود اسکریپت دارید، Pull Request بفرستید یا توی Issues مطرح کنید. -------------------------------------------------------------------------------- /pingtunnel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then 4 | echo "This script must be run as root" 5 | sleep 1 6 | exit 1 7 | fi 8 | 9 | press_key() { 10 | read -p "Press any key to continue..." 11 | } 12 | 13 | purple="\033[35m" 14 | green="\033[32m" 15 | orange="\033[33m" 16 | blue="\033[34m" 17 | red="\033[31m" 18 | cyan="\033[36m" 19 | white="\033[37m" 20 | reset="\033[0m" 21 | 22 | colorize() { 23 | local color="$1" 24 | local text="$2" 25 | local style="${3:-normal}" 26 | 27 | local purple="\033[35m" 28 | local green="\033[32m" 29 | local orange="\033[33m" 30 | local blue="\033[34m" 31 | local red="\033[31m" 32 | local cyan="\033[36m" 33 | local white="\033[37m" 34 | local reset="\033[0m" 35 | 36 | local normal="\033[0m" 37 | local bold="\033[1m" 38 | local underline="\033[4m" 39 | 40 | local color_code 41 | case $color in 42 | purple) color_code=$purple ;; 43 | green) color_code=$green ;; 44 | orange) color_code=$orange ;; 45 | blue) color_code=$blue ;; 46 | red) color_code=$red ;; 47 | cyan) color_code=$cyan ;; 48 | white) color_code=$white ;; 49 | *) color_code=$reset ;; 50 | esac 51 | 52 | local style_code 53 | case $style in 54 | bold) style_code=$bold ;; 55 | underline) style_code=$underline ;; 56 | normal | *) style_code=$normal ;; 57 | esac 58 | 59 | echo -e "${style_code}${color_code}${text}${reset}" 60 | } 61 | 62 | install_unzip() { 63 | if ! command -v unzip &> /dev/null; then 64 | if command -v apt-get &> /dev/null; then 65 | colorize orange "unzip is not installed. Installing..." bold 66 | sleep 1 67 | sudo apt-get update 68 | sudo apt-get install -y unzip 69 | else 70 | colorize red "Error: Unsupported package manager. Please install unzip manually." bold 71 | press_key 72 | exit 1 73 | fi 74 | fi 75 | } 76 | 77 | install_unzip 78 | 79 | install_curl() { 80 | if ! command -v curl &> /dev/null; then 81 | if command -v apt-get &> /dev/null; then 82 | colorize orange "curl is not installed. Installing..." bold 83 | sleep 1 84 | sudo apt-get update 85 | sudo apt-get install -y curl 86 | else 87 | colorize red "Error: Unsupported package manager. Please install curl manually." bold 88 | press_key 89 | exit 1 90 | fi 91 | fi 92 | } 93 | 94 | install_curl 95 | 96 | config_dir="/root/pingtunnel-core" 97 | service_dir="/etc/systemd/system" 98 | 99 | download_and_extract_pingtunnel() { 100 | if [[ -f "${config_dir}/pingtunnel" ]]; then 101 | return 0 102 | fi 103 | 104 | if [[ $(uname) == "Linux" ]]; then 105 | ARCH=$(uname -m) 106 | case $ARCH in 107 | x86_64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_amd64.zip" ;; 108 | arm*) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_arm.zip" ;; 109 | aarch64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_arm64.zip" ;; 110 | mips) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_mips.zip" ;; 111 | mipsel) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_mipsle.zip" ;; 112 | mips64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_mips64.zip" ;; 113 | mips64el) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_mips64le.zip" ;; 114 | ppc64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_ppc64.zip" ;; 115 | ppc64le) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_ppc64le.zip" ;; 116 | riscv64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_riscv64.zip" ;; 117 | s390x) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_s390x.zip" ;; 118 | i386 | i686) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_386.zip" ;; 119 | loong64) DOWNLOAD_URL="https://github.com/esrrhs/pingtunnel/releases/download/2.8/pingtunnel_linux_loong64.zip" ;; 120 | *) colorize red "Unsupported architecture: $ARCH" bold; sleep 1; exit 1 ;; 121 | esac 122 | else 123 | colorize red "Unsupported operating system." bold 124 | sleep 1 125 | exit 1 126 | fi 127 | 128 | if [ -z "$DOWNLOAD_URL" ]; then 129 | colorize red "Failed to determine download URL." bold 130 | sleep 1 131 | exit 1 132 | fi 133 | 134 | DOWNLOAD_DIR=$(mktemp -d) 135 | colorize blue "Downloading PingTunnel from $DOWNLOAD_URL..." bold 136 | sleep 1 137 | curl -sSL -o "$DOWNLOAD_DIR/pingtunnel.zip" "$DOWNLOAD_URL" 138 | colorize blue "Extracting PingTunnel..." bold 139 | sleep 1 140 | mkdir -p "$config_dir" 141 | unzip -q "$DOWNLOAD_DIR/pingtunnel.zip" -d "$config_dir" 142 | chmod +x "${config_dir}/pingtunnel" 143 | echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all 144 | colorize green "PingTunnel installation completed." bold 145 | rm -rf "$DOWNLOAD_DIR" 146 | } 147 | 148 | display_logo() { 149 | echo -e "${purple}" 150 | cat << "EOF" 151 | ______ _____ _ _ _____ _____ _ _ _ _ _ _ _____ _ 152 | | ___ \_ _| \ | | __ \ |_ _| | | | \ | || \ | || ___| | 153 | | |_/ / | | | \| | | \/ | | | | | | \| || \| || |__ | | 154 | | __/ | | | . ` | | __ | | | | | | . ` || . ` || __|| | 155 | | | _| |_| |\ | |_\ \ | | | |_| | |\ || |\ || |___| |____ 156 | \_| \___/\_| \_/\____/ \_/ \___/\_| \_/\_| \_/\____/\_____/ 157 | EOF 158 | colorize green "Version: ${orange}v1.0${reset}" bold 159 | colorize green "Github: ${orange}github.com/ppouria/ping-tunnel${reset}" bold 160 | colorize green "Telegram Channel: ${orange}@MarzHelp${reset}" bold 161 | } 162 | 163 | display_server_info() { 164 | SERVER_IP=$(hostname -I | awk '{print $1}') 165 | SERVER_COUNTRY=$(curl --max-time 3 -sS "http://ipwhois.app/json/$SERVER_IP" | jq -r '.country' 2>/dev/null || echo "Unknown") 166 | SERVER_ISP=$(curl --max-time 3 -sS "http://ipwhois.app/json/$SERVER_IP" | jq -r '.isp' 2>/dev/null || echo "Unknown") 167 | colorize cyan "═════════════════════════════════════════════" 168 | colorize cyan "Location: ${green}${SERVER_COUNTRY}${cyan}" 169 | colorize cyan "Datacenter: ${green}${SERVER_ISP}${cyan}" 170 | } 171 | 172 | display_pingtunnel_status() { 173 | if [[ -f "${config_dir}/pingtunnel" ]]; then 174 | colorize cyan "PingTunnel Core: ${green}Installed${cyan}" 175 | else 176 | colorize cyan "PingTunnel Core: ${red}Not installed${cyan}" 177 | fi 178 | colorize cyan "═════════════════════════════════════════════" 179 | } 180 | 181 | check_port() { 182 | local port=$1 183 | if [[ "$port" =~ ^[0-9]+$ ]] && [ "$port" -gt 1024 ] && [ "$port" -le 65535 ]; then 184 | if ss -tln | grep -q ":$port "; then 185 | colorize red "Port $port is already in use." bold 186 | return 1 187 | else 188 | return 0 189 | fi 190 | else 191 | colorize red "Invalid port. Please enter a number between 1025 and 65535." bold 192 | return 1 193 | fi 194 | } 195 | 196 | configure_tunnel() { 197 | if [[ ! -f "${config_dir}/pingtunnel" ]]; then 198 | colorize red "PingTunnel is not installed. Please install it first." bold 199 | press_key 200 | return 1 201 | fi 202 | 203 | clear 204 | colorize blue "Configure PingTunnel" bold 205 | echo 206 | colorize green "1) Configure for Iran server" bold 207 | colorize green "2) Configure for Kharej server" bold 208 | echo 209 | read -p "Enter your choice [1-2]: " choice 210 | case $choice in 211 | 1) iran_server_configuration ;; 212 | 2) kharej_server_configuration ;; 213 | *) colorize red "Invalid option!" bold; sleep 1; return 1 ;; 214 | esac 215 | press_key 216 | } 217 | 218 | iran_server_configuration() { 219 | clear 220 | colorize blue "Configuring Iran Server" bold 221 | echo 222 | 223 | while true; do 224 | read -p "[*] Enter Kharej server IP: " kharej_ip 225 | if [[ "$kharej_ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then 226 | break 227 | else 228 | colorize red "Invalid IP address. Please enter a valid IPv4 address." bold 229 | fi 230 | done 231 | 232 | while true; do 233 | read -p "[*] Enter tunnel port: " tunnel_port 234 | if check_port "$tunnel_port"; then 235 | break 236 | fi 237 | done 238 | 239 | cat << EOF > "${service_dir}/pingtunnel-iran${tunnel_port}.service" 240 | [Unit] 241 | Description=PingTunnel Iran Client (Port $tunnel_port) 242 | After=network.target 243 | 244 | [Service] 245 | Type=simple 246 | ExecStart=${config_dir}/pingtunnel -type client -l :${tunnel_port} -s ${kharej_ip} -t 127.0.0.1:${tunnel_port} -tcp 1 247 | Restart=always 248 | RestartSec=3 249 | 250 | [Install] 251 | WantedBy=multi-user.target 252 | EOF 253 | 254 | systemctl daemon-reload >/dev/null 2>&1 255 | if systemctl enable --now "pingtunnel-iran${tunnel_port}.service" >/dev/null 2>&1; then 256 | colorize green "Iran tunnel service on port $tunnel_port started and enabled." bold 257 | else 258 | colorize red "Failed to start Iran tunnel service on port $tunnel_port." bold 259 | return 1 260 | fi 261 | 262 | colorize green "Iran server configuration completed successfully." bold 263 | } 264 | 265 | kharej_server_configuration() { 266 | clear 267 | colorize blue "Configuring Kharej Server" bold 268 | echo 269 | 270 | cat << EOF > "${service_dir}/pingtunnel-kharej.service" 271 | [Unit] 272 | Description=PingTunnel Kharej Server 273 | After=network.target 274 | 275 | [Service] 276 | Type=simple 277 | ExecStart=${config_dir}/pingtunnel -type server 278 | Restart=always 279 | RestartSec=3 280 | 281 | [Install] 282 | WantedBy=multi-user.target 283 | EOF 284 | 285 | systemctl daemon-reload >/dev/null 2>&1 286 | if systemctl enable --now "pingtunnel-kharej.service" >/dev/null 2>&1; then 287 | colorize green "Kharej server service started and enabled." bold 288 | else 289 | colorize red "Failed to start Kharej server service." bold 290 | return 1 291 | fi 292 | 293 | colorize green "Kharej server configuration completed successfully." bold 294 | } 295 | 296 | check_tunnel_status() { 297 | clear 298 | colorize blue "Checking Tunnel Status" bold 299 | echo 300 | 301 | local found=0 302 | for service in $(systemctl list-units --type=service | grep pingtunnel | awk '{print $1}'); do 303 | found=1 304 | if systemctl is-active --quiet "$service"; then 305 | colorize green "$service is running" bold 306 | else 307 | colorize red "$service is not running" bold 308 | fi 309 | done 310 | 311 | if [ $found -eq 0 ]; then 312 | colorize red "No PingTunnel services found." bold 313 | fi 314 | 315 | press_key 316 | } 317 | 318 | tunnel_management() { 319 | clear 320 | colorize blue "Tunnel Management Menu" bold 321 | echo 322 | 323 | local index=1 324 | declare -a services 325 | 326 | for service in $(systemctl list-units --type=service | grep pingtunnel | awk '{print $1}'); do 327 | services+=("$service") 328 | echo -e "${cyan}${index}${reset}) ${green}${service}${reset}" 329 | ((index++)) 330 | done 331 | 332 | if [ ${#services[@]} -eq 0 ]; then 333 | colorize red "No PingTunnel services found." bold 334 | press_key 335 | return 1 336 | fi 337 | 338 | echo 339 | read -p "Select a service (0 to return): " choice 340 | if [ "$choice" == "0" ]; then 341 | return 342 | fi 343 | 344 | if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#services[@]} ]; then 345 | colorize red "Invalid choice." bold 346 | sleep 1 347 | return 1 348 | fi 349 | 350 | selected_service="${services[$((choice - 1))]}" 351 | clear 352 | colorize blue "Manage $selected_service" bold 353 | echo 354 | colorize green "1) Restart service" bold 355 | colorize red "2) Stop service" bold 356 | colorize red "3) Delete service" bold 357 | colorize cyan "4) View service logs" bold 358 | colorize cyan "5) View service status" bold 359 | echo 360 | read -p "Enter your choice [0-5]: " action 361 | case $action in 362 | 1) systemctl restart "$selected_service"; colorize green "Service restarted." bold ;; 363 | 2) systemctl stop "$selected_service"; colorize red "Service stopped." bold ;; 364 | 3) systemctl disable --now "$selected_service" >/dev/null 2>&1; rm -f "${service_dir}/${selected_service}"; systemctl daemon-reload; colorize red "Service deleted." bold ;; 365 | 4) journalctl -eu "$selected_service";; 366 | 5) systemctl status "$selected_service";; 367 | 0) return ;; 368 | *) colorize red "Invalid option!" bold; sleep 1 ;; 369 | esac 370 | press_key 371 | } 372 | 373 | display_menu() { 374 | clear 375 | display_logo 376 | display_server_info 377 | display_pingtunnel_status 378 | echo 379 | colorize green "1. Configure a new tunnel" bold 380 | colorize red "2. Tunnel management menu" bold 381 | colorize cyan "3. Check tunnels status" bold 382 | colorize orange "4. Install PingTunnel core" bold 383 | colorize red "5. Remove PingTunnel core" bold 384 | colorize white "0. Exit" bold 385 | echo 386 | echo "-------------------------------" 387 | } 388 | 389 | read_option() { 390 | read -p "Enter your choice [0-5]: " choice 391 | case $choice in 392 | 1) configure_tunnel ;; 393 | 2) tunnel_management ;; 394 | 3) check_tunnel_status ;; 395 | 4) download_and_extract_pingtunnel "sleep" ;; 396 | 5) remove_core ;; 397 | 0) exit 0 ;; 398 | *) colorize red "Invalid option!" bold; sleep 1 ;; 399 | esac 400 | } 401 | 402 | remove_core() { 403 | clear 404 | colorize blue "Remove PingTunnel Core" bold 405 | echo 406 | 407 | if find "$service_dir" -type f -name "pingtunnel-*.service" | grep -q .; then 408 | colorize red "Active services found. Please delete all services before removing PingTunnel core." bold 409 | press_key 410 | return 1 411 | fi 412 | 413 | read -p "Are you sure you want to remove PingTunnel core? (y/n): " confirm 414 | if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then 415 | if [[ -d "$config_dir" ]]; then 416 | rm -rf "$config_dir" 417 | colorize green "PingTunnel core removed successfully." bold 418 | else 419 | colorize red "PingTunnel core directory not found." bold 420 | fi 421 | else 422 | colorize orange "PingTunnel core removal canceled." bold 423 | fi 424 | press_key 425 | } 426 | 427 | download_and_extract_pingtunnel 428 | 429 | while true; do 430 | display_menu 431 | read_option 432 | done --------------------------------------------------------------------------------