@echo off&color1E&title GTIIT-NETWORK-SWITCH-TOOL echo --------------------------------------------------------------------------------------------- echo * * echo * To switch the network environment, select your current network condition(FOR WIFI) * echo * Need to run as Administrator!!! * echo * By GTIIT-Zach github.com/cszmzh * echo * * echo --------------------------------------------------------------------------------------------- >nul2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:choice set choice= set /p choice= Restore Network Config please input 1, For GTIIT-Campus-Network please input 2 and enter: [1,2] ? if%choice%==2goto school_lan if%choice%==1 (goto lab_lan) else (echo ERROR, please input again&goto choice)
:lab_lan set eth="WLAN" set ip= set netmask= set gw= set dns1= set dns2= echo. echoRestore to default network configuration echo. goto public
:school_lan set eth="WLAN" set ip=10.211.137. set netmask=255.255.0.0 set gw=10.211.0.1 set dns1=10.150.4.13 set dns2=10.103.4.10 echo. echo Switch to GITTI Campus network configuration echo. goto switch
:switch set code= set /p code= input your IP number[3-254] %ip% set "ip=%ip%%code%" echo Setting the IP address to %ip% netsh interface ip set address %eth% static %ip%%netmask%%gw%1 echo Setting the DNS1 address to %dns1% netsh interface ip set dns %eth% static %dns1% register=PRIMARY validate=no ifdefined dns2 ( echo Setting the DNS2 address to %dns2% netsh interface ip add dns %eth%%dns2% index=2 validate=no ) echo. echo IP setting succeeded: %ip% echo. goto end
:public echo Setting the IP address to automatically obtain netsh interface ip set address %eth% dhcp echo Setting the DNS address to automatically obtain netsh interface ip set dns %eth% dhcp echo Obtaining IP automatically, hang on for a while... echo.
::for /L %%xin (1110) doset /p gu=<nul&ping /n 2127.1>nul for /f "tokens=16" %%iin ('ipconfig ^|find /i "ipv4"') do ( set myip=%%i :: 正常情况下find查询只有一行结果,如果主机安装了虚拟机则会有多个适配器有ip地址。第一个才是本机IP,故使用goto保证for只执行一次就跳出循环,防止后续myip的值被覆盖 goto out ) :out echo Get local IP: %myip%
echo100%% echo. echo The network is restored successfully. Everything is the default configuration. echo. goto end
@echo off&color1E&title GTIIT-NETWORK-SWITCH-TOOL echo --------------------------------------------------------------------------------------------- echo * * echo * To switch the network environment, select your current network condition(FOR WIFI) * echo * Need to run as Administrator!!! * echo * By GTIIT-Zach github.com/cszmzh * echo * * echo --------------------------------------------------------------------------------------------- >nul2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:choice set choice= set /p choice= Restore Network Config please input 1, For GTIIT-Campus-Network please input 2 and enter: [1,2] ? if%choice%==2goto school_lan if%choice%==1 (goto lab_lan) else (echo ERROR, please input again&goto choice)
:lab_lan set eth="WLAN" set ip= set netmask= set gw= set dns1= set dns2= echo. echoRestore to default network configuration echo. goto public
:school_lan set eth="WLAN" set dns1=10.150.4.13 set dns2=10.103.4.10 echo. echo Switch to GITTI Campus network configuration echo. goto switch
:switch echo Setting the DNS1 address to %dns1% netsh interface ip set dns %eth% static %dns1% register=PRIMARY validate=no ifdefined dns2 ( echo Setting the DNS2 address to %dns2% netsh interface ip add dns %eth%%dns2% index=2 validate=no ) echo. goto end
:public echo Setting the IP address to automatically obtain netsh interface ip set address %eth% dhcp echo Setting the DNS address to automatically obtain netsh interface ip set dns %eth% dhcp echo Obtaining IP automatically, hang on for a while... echo.
::for /L %%xin (1110) doset /p gu=<nul&ping /n 2127.1>nul for /f "tokens=16" %%iin ('ipconfig ^|find /i "ipv4"') do ( set myip=%%i :: 正常情况下find查询只有一行结果,如果主机安装了虚拟机则会有多个适配器有ip地址。第一个才是本机IP,故使用goto保证for只执行一次就跳出循环,防止后续myip的值被覆盖 goto out ) :out echo Get local IP: %myip%
echo100%% echo. echo The network is restored successfully. Everything is the default configuration. echo. goto end
@Echo Off For /F "Skip=1Delims=" %%aIn ( '"WMIC NIC Where (Not NetConnectionStatus Is Null) Get NetConnectionID"' ) DoFor /F "Tokens=*" %%bIn ("%%a") DoEcho=%%b Timeout -1