bash regex ip address code example

Example 1: ip address regex validate cmd

#!/bin/sh

ip=1.2.3.4

if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
  echo "success"
else
  echo "fail"
fi

Example 2: ip address regex validate cmd

echo off
:start
cls

set /p localWireless=input wireless ip address ? &
echo %localWireless% | findstr /i /r [0-9].*.[.].*.[0-9].*.[.].*.[0-9]

if %errorlevel% equ 0  (
  goto installLocalWireless
) else (
  msg %username% 'ip address is not valid'
  goto start
)

:installLocalWireless
cls
echo Hello Wordl
pause
goto start