stunnel 相关的批处理

批处理
@echo off
setlocal enabledelayedexpansion
::color f0
mode con cols=40 lines=25
cd "%cd%"
echo.
echo 正在停止 stunnel
echo.
tasklist /nh|find /i "stunnel.exe"
if ERRORLEVEL 1 (goto :stop)
:stop
taskkill /f /im stunnel.exe
echo.
echo stunnel 已停止
echo.
title 正在更新服务器
rem Create server list
echo.
echo 正在更新服务器,请稍候...
echo.
curl --silent --url http://stunnel.yourshell.info/ --output ServerList.txt
echo.
echo 正在查找最快的服务器,请稍候...
echo.
echo.>ServerIP.txt
(for /f "usebackq tokens=1-2" %%a in (ServerList.txt) do (
  call :GetIP %%a
))>>PingIP.txt
rem Get response time
for /f "usebackq tokens=1-3" %%a in (PingIP.txt) do (
  set /p=Checking on %%a %%b %%c<nul
  for /f "skip=11 tokens=10 delims=m= " %%h in ('ping %%a') do (
    echo %%a %%hms>>ServerIP.txt
    set strTime=0000%%h
    set strTime=!strTime:~-5!
    set _arrayTime_!strTime!=%%a_%%b_%%c
  )
)
rem Find best server
for /f "tokens=2-5 delims=_=" %%a in ('set _arrayTime') do (
  set BestServer=%%c
  set BestIP=%%b
  set BestType=%%d
  set BestTime=1%%a
  set /a BestTime%%=100000
  goto :End
)
:GetIP
for /f "skip=2 tokens=3,8 delims=:= " %%h in ('ping -n 1 -l 1 %1') do (
  if "%%i" equ "TTL" (
    echo %%h %1 %2
  )
)
goto :eof
:End
echo.
echo.
echo 最快服务器:%BestServer% %BestTime%ms %BestType%
echo.
echo client = yes>stunnel.conf
echo.>>stunnel.conf
echo [SSL Proxy]>>stunnel.conf
echo accept = 127.0.0.1:8081>>stunnel.conf
echo connect = %BestIP%:443>>stunnel.conf
del /Q ServerList.txt
del /Q PingIP.txt
echo 启动 stunnel
start /min stunnel
goto :eof

 

原文链接:,转发请注明来源!

发表评论