1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| @echo off
mode con cols=42 lines=30
title %~nx0
setlocal enableextensions enabledelayedexpansion
ver | find "10.0." >nul && chcp 65001 >nul || chcp 28591 >nul
:: --------------------------------------------------------------------------------------
:: on vérifie si le script est bien lancé en tant qu'administrateur
:: --------------------------------------------------------------------------------------
attrib %windir%\system32 -h | findstr /i "system32" >nul && exit /b 1
:: --------------------------------------------------------------------------------------
:: on définit les paramètres
:: --------------------------------------------------------------------------------------
set action="00000001"
set proxy="http=127.0.0.1:8888;https=127.0.0.1:8888;ftp=127.0.0.1:8888;socks=127.0.0.1:8888"
set adresse_debut="10.6.148.200"
set adresse_fin="10.6.148.220"
for /f "tokens=4 delims=. " %%A in (%adresse_debut%) do set "debut=%%A"
for /f "tokens=4 delims=. " %%A in (%adresse_fin%) do set "fin=%%A"
for /f "tokens=1-3 delims=." %%A in (%adresse_debut%) do set "reseau=%%A.%%B.%%C"
:: --------------------------------------------------------------------------------------
:: on modifie l'adressage de la carte réseau filaire
:: --------------------------------------------------------------------------------------
netsh interface ipv4 set address "Ethernet" static 10.6.148.170 255.255.255.0 10.6.148.1 1
:: --------------------------------------------------------------------------------------
:: on active le proxy
:: --------------------------------------------------------------------------------------
rem Décommenter la ligne ci-dessous pour basculer automatiquement entre l'état "activé" et "désactivé"
rem for /f "tokens=3" %%A in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /V "ProxyEnable"') do if "%%A"=="0x0" (set action="00000001") else (set action="00000000")
>nul reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /V "ProxyServer" /T REG_SZ /D %proxy% /F
>nul reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /V "ProxyEnable" /T REG_DWORD /D %action% /F
cls & echo. & if %action%=="00000001" (echo ########## Proxy activé ##########) else (echo ########## Proxy désactivé ##########)
:: --------------------------------------------------------------------------------------
:: on teste la connectivité
:: --------------------------------------------------------------------------------------
for /L %%E in (%debut%,1,%fin%) do (
for /f "delims=" %%A in ('ping %reseau%.%%E -n 3') do set "result=%%A"
set "status=FAILED"
echo !result! | find "0%" | find /v "100%" >nul && set "status=OK"
echo !result! | find "33%" >nul && set "status=OK"
echo. & echo ^>^>^> %reseau%.%%E !status!
)
echo. & pause
exit |