garybsimon
garybsimon

Reputation: 3

How to check IP range and create IF THEN via windows batch file?

I want to create a Windows Batch script (.bat) file. First of all I need to check the computer IP address and when its in a predefinied range like 172.18.. then the script will run toward else the script will go to exit. Please let me know how to made it in the easy way. Thank you.

Upvotes: 0

Views: 1839

Answers (1)

Matt Williamson
Matt Williamson

Reputation: 7095

This should get you started.

@echo off
setlocal

for /f "tokens=2 delims=:" %%a in ('ipconfig^|find "IP Address"') do (
    for /f "tokens=1,2 delims=." %%b in ('echo %%a') do ( 
        if "%%b.%%c"==" 172.18" (echo do stuff) else echo no match. exiting&exit /b 1
    )
)   

Upvotes: 1

Related Questions