jslegers Posted February 15, 2010 Posted February 15, 2010 Hello,I want to create a batch file that can check on IP range to do something.Simple exampleIf ip range = 192.168.10.1 - 192.168.10.255 then install1.batIf ip range = 192.168.20.1 - 192.168.20.255 then install2.batIf ip range = 192.168.30.1 - 192.168.30.255 then install3.batIs this possible ?
jaclaz Posted February 15, 2010 Posted February 15, 2010 What do you mean by IP range?The subnet mask?Or the Lan card IP?Something like this:http://www.robvanderwoude.com/ntfortokens.phpYou can parse the IPCONFIG /ALL command output.jaclaz
jslegers Posted February 16, 2010 Author Posted February 16, 2010 What do you mean by IP range?The subnet mask?Or the Lan card IP?Something like this:http://www.robvanderwoude.com/ntfortokens.phpYou can parse the IPCONFIG /ALL command output.jaclazSomething like that yes. I will check it out. Thanks.
gunsmokingman Posted February 16, 2010 Posted February 16, 2010 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.vbsDim 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now