::rem ############# huaweilib.bat ####################
::@echo off
call %*
goto:eof
:get_adgrp
setlocal
::it require two argument: the policy number and the out address-group variable name
::call:get_adgrp 3 grpno
set spyarg=%1
if not defined spyarg (
echo No policy number specified!
exit /b
)
set “is_num=”
call:is_num %1
if [%is_num%] == [false] (
echo argument is not a number!
exit /b
)
echo echo yes ^| plink -agent -ssh -1 -l jhrwgly -pw CorpName2014^^! -P 22222 172.16.8.2 display nat-policy interzone trust untrust outbound policy %1 2^>nul ^| findstr address-group ^> getadgrp.txt > getadgrp.bat
echo exit >> getadgrp.bat
start /min /wait getadgrp.bat
for /f “tokens=2” %%i in ( getadgrp.txt ) do set adgrp=%%i
:end_get_adgrp
endlocal & set /a %2=%adgrp%
goto:eof
:get_uniq_random
setlocal enabledelayedexpansion
set /a argcount=0
for %%i in ( %* ) do set /a argcount+=1
if %argcount% equ 0 (
echo No random number variable argument!
exit /b
)
set arg1=%1
shift
set /a argcount-=1
:isunique
set “in1=”
set /a in1=”%random% %% 6 + 3″
for /l %%j in (1,1,%argcount%) do (
set /a index=%%j
call echo %%!index!>indexfile
set /p index2=<indexfile
if [%in1%] equ [!index2!] goto:isunique
)
:end_get_uniq_random
endlocal & set /a “%arg1%=%in1%”
goto:eof
:set_adgrp
setlocal
rem accept two arguments, first the source NAT policy number, second the new address-group number
set /a argcount=0
for %%i in ( %* ) do set /a argcount+=1
if %argcount% neq 2 (
echo Need two arguments! policy number and new address-group number!
goto:end_set_adgrp
)
for %%i in ( %* ) do (
set “is_num=”
call:is_num %%i
if [%is_num%] == [false] (
echo Arguments are not numbers!
goto:end_set_adgrp
)
)
)
echo sys > set_adgrp.txt
echo nat-policy interzone trust untrust outbound >> set_adgrp.txt
echo policy %1 >> set_adgrp.txt
echo address-group %2 >> set_adgrp.txt
echo quit >> set_adgrp.txt
echo quit >> set_adgrp.txt
echo quit >> set_adgrp.txt
echo quit >> set_adgrp.txt
echo yes | plink -agent -ssh -1 -l jhrwgly -pw CorpName2014! -P 22222 172.16.8.2 < set_adgrp.txt
:end_set_adgrp
endlocal
goto:eof
:is_num
setlocal
set spyisnumarg=%1
if not defined spyisnumarg (
echo no argument specified.
exit /b
)
set “notnum=” & for /f “delims=0123456789” %%i in ( “%1” ) do set notnum=%%i
:end_is_num
endlocal & (
if [%notnum%] == [] (set is_num=true) else (set is_num=false)
)
goto:eof
::rem ################### huaweichgadgrp #########################
@echo off
setlocal enabledelayedexpansion
echo original address-group for source NAT policy 3,4,5 is:
for /l %%a in (3,1,5) do (
set “grpno=”
call huaweilib.bat :get_adgrp %%a grpno_%%a
echo.policy %%a’s group number is !grpno_%%a!
)
call huaweilib.bat :get_uniq_random newpol3adgrp %grpno_3% %grpno_4% %grpno_5%
call huaweilib.bat :get_uniq_random newpol4adgrp %newpol3adgrp% %grpno_3% %grpno_4% %grpno_5%
call huaweilib.bat :get_uniq_random newpol5adgrp %newpol4adgrp% %newpol3adgrp% %grpno_3% %grpno_4% %grpno_5%
if exist set_adgrp.bat del /f set_adgrp.bat
echo @echo off > set_adgrp.bat
for /l %%i in (3,1,5) do (echo call huaweilib.bat :set_adgrp %%i !newpol%%iadgrp! >> set_adgrp.bat)
echo exit >> set_adgrp.bat
endlocal
start /WAIT /MIN set_adgrp.bat
setlocal enabledelayedexpansion
echo new address-group for source NAT policy 3,4,5 is:
for /L %%i in (3,1,5) do (
set “grpno=”
call huaweilib.bat :get_adgrp %%i grpno_%%i
echo.policy %%i’s new group number is !grpno_%%i!
)
timeout /t 5
exit