Jump to content

Batch file that checks IP range


jslegers

Recommended Posts

Hello,

I want to create a batch file that can check on IP range to do something.

Simple example

If ip range = 192.168.10.1 - 192.168.10.255 then install1.bat

If ip range = 192.168.20.1 - 192.168.20.255 then install2.bat

If ip range = 192.168.30.1 - 192.168.30.255 then install3.bat

Is this possible ?

Link to comment
Share on other sites


I wrote up this VBS script and it should do what you want, I have it so it will just display the results.

If you get the results you want I will add the cmd that you need to run.

Save CheckIpRunCmd.vbs


Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Dim Ip, Z1, Z2
'-> Loop To Get Local Machine IP
For Each Obj in Wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
If not isNull(Obj.IPSubnet) Then
If not isNull(Obj.IPAddress) Then
Z1 = Join(Obj.IPAddress, ",")
If Len(Z1) <= 15 Then
Ip = Z1
ElseIf Len(Z1) >= 16 Then
'-> Vista And Win 7 Return Ipv4 And Ipv6 This Gets Ipv4 Address
Z2 = Split(Z1, ",")
Ip = Z2(0)
End If
End If
End If
Next
'-> Compare IP
If Ip > "192.168.10.1" And Ip < "192.168.10.255" Then
WScript.Echo "Confirm Ip " & Ip & vbCrLf & "Run Cmd 1"
ElseIf Ip > "192.168.20.1" And Ip < "192.168.20.255" Then
WScript.Echo "Confirm Ip " & Ip & vbCrLf & "Run Cmd 2"
ElseIf Ip > "192.168.30.1" And "Ip" < "192.168.30.255" Then
WScript.Echo "Confirm Ip " & Ip & vbCrLf & "Run Cmd 3"
Else
WScript.Echo "Ip Address Is Not Within Search Range" & vbCrLf & "Ip Address " & Ip
End If

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...