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
| @echo off
Title Test the validity of an IP address IPv4 Or IPv6
ECHO( Tapez votre adresse IP :
set /P "_IP="
Call :CheckIp "%_IP%" Validity
if [%Validity%] equ [0] (
color 0A
echo "%_IP%" is a valid ip
) else (
Color 0C
echo "%_IP%" is not a valid ip
)
Pause
Exit
::--------------------------------------------------------------------------------------------------
:CheckIP <IP> <Validity>
Set "VbsFile=%Temp%\%~n0.vbs"
(
echo WScript.Echo(Is_Valid("%~1"^)^)
echo Function Is_Valid(ip^)
echo Dim RegularExpressionObject
echo Set RegularExpressionObject = New RegExp
echo With RegularExpressionObject
echo .Pattern = "(^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$)|(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
echo .IgnoreCase = False
echo If .Test(ip^)= True then
echo Is_Valid = 0
echo Else
echo Is_Valid = 1
echo End if
echo End With
echo End Function
)>"%VbsFile%"
@for /f "delims=" %%a in ('cscript //nologo "%VbsFile%"') do set "%2=%%a"
Exit /B
::-------------------------------------------------------------------------------------------------- |
Partager