Check Subnet IP then run command based off it's value

I'm having some difficulty getting this to work, but I have 2 LANs .111 and .112 -- what I would like to have is a script that accomplishes the following:

Check local computer's IP address to determine subnet (192.168.x.0) and then execute a command based off whether the match is 111 or 112.

Hope that makes sense, thanks in advance!
Uptime Legal SystemsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
$ipaddresses = get-netipaddress -AddressFamily IPv4 | select interfacealias,ipaddress
foreach ($ip in $ipaddresses) {
if ($ip.ipaddress -like '192.168.111.*')
write-output $ip.ipaddress
elseif ($ip.address -like '192.168.112.*')
    Write-Output $ip.ipaddress
    else {
    Write-Output ($ip.interfacealias + "     " + $ip.ipaddress)

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
Here is a BAT script approach that should get you started, just add the logic you need.

@echo off

for /f "tokens=2 delims={};" %%A in ('wmic nicconfig get ipaddress /format:csv') do (
  for /f "tokens=3 delims=." %%B in ("%%~A") do (
    if "%%B" == "111" (
      echo 111 Found in IP address "%%~A"
      rem Add commands here...
    if "%%B" == "112" (
      echo 112 Found in IP address "%%~A"
      rem Add commands here...

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Uptime Legal SystemsAuthor Commented:
Both very good approaches!  Appreciate the technical expertise, gentlemen.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.