Elephant007 Posted December 4, 2010 Share Posted December 4, 2010 I would like to make a script based on the IP Address of the computer on our domain, we use 10. IP Address schemes Basically I need to check @IPAdress1 and @IPAdress2, The problem I'm running into is if either @IPAddress1 or @IPAddress2 equals 0.0.0.0 I don't know how to have my script only use a valid 10.x.x.x IP Address. I use StringSplit to get the first octet, to make sure it's a valid IP I use StringSplit to get the second octet which tells me the computers location Just don't know how to 'find' the valid IP and not use the 0.0.0.0 IP Thank you in advance for any help! Link to comment Share on other sites More sharing options...
Necromorph Posted December 4, 2010 Share Posted December 4, 2010 (edited) im not sure i follow you but maybe this: If @IPAddress1 Then ;==> your code here Elseif @IPAddress2 Then ;==> your alternate code here Else ;==> this is assuming your that ip1 and ip2 failed, so it is 0.0.0.0 ;==> your code for 0.0.0.0 EndIf Edited December 4, 2010 by redLabel Link to comment Share on other sites More sharing options...
Elephant007 Posted December 4, 2010 Author Share Posted December 4, 2010 (edited) im not sure i follow you but maybe this: If @IPAddress1 Then ;==> your code here Elseif @IPAddress2 ;==> your alternate code here Else ;==> this is assuming your that ip1 and ip2 failed, so it is 0.0.0.0 ;==> your code for 0.0.0.0 EndIf Thanks for your quick reply. What you've given me means that I would have to write the same code twice for each @IPAddress Let me see if I can explain myself better We have computers and laptops on our domain. Wired connection uses @IPAddress2 and Wireless uses @IPAddress2 In my script I need to eliminate any address that does not start with 10. So if @IPAddress2 = 0.0.0.0 Then my script knows to use @IPAddress1 I can then strip down the IP Address to the second octet I can script the rest Edited December 4, 2010 by Elephant007 Link to comment Share on other sites More sharing options...
Varian Posted December 4, 2010 Share Posted December 4, 2010 (edited) As an example_IPRule(@IPAddress1) _IPRule(@IPAddress2) Func _IPRule($IPaddress) $IPArray = StringSplit($IPaddress, '.', 2) If Not IsArray($IPArray) Or UBound($IPArray) <> 4 Then Return MsgBox(0, 'Error', '$IPArray is not an array') If $IPArray[0] = 0 Then Return MsgBox(0, 'ERROR', 'Bad IP Address') If $IPArray[0] = 10 Then Switch $IPArray[1] Case 1 To 100 MsgBox(0, 'Location', 'Location is in the 0 - 100') ;do something else here if you want Case 100 To 200 MsgBox(0, 'Location', 'Location is in the 100 - 200') ;do something else here if you want Case 201 To 255 MsgBox(0, 'Location', 'Location is in the 201 - 255') ;do something else here if you want EndSwitch Else Return MsgBox(0, 'Unknown Location', 'IP Address is: ' & $IPaddress) EndIf EndFunc ;==>_IPRule EDIT...This may be a little better for your needs (to get you started with your logic)Local $IPList[4] = [@IPAddress1,@IPAddress2,@IPAddress3,@IPAddress4] For $Element In $IPList _IPRule($Element) Next Func _IPRule($IPaddress) Local $IPArray = StringSplit($IPaddress, '.', 2) If Not IsArray($IPArray) Or UBound($IPArray) <> 4 Then Return MsgBox(0, 'Error', '$IPArray is not an array') If $IPArray[0] = 0 Then Return MsgBox(0, 'ERROR', 'Bad IP Address') If $IPArray[0] = 10 Then Switch $IPArray[1] Case 1 To 100 MsgBox(0, 'Location', 'Location is in the 0 - 100') ;do something else here if you want Case 100 To 200 MsgBox(0, 'Location', 'Location is in the 100 - 200') ;do something else here if you want Case 201 To 255 MsgBox(0, 'Location', 'Location is in the 201 - 255') ;do something else here if you want EndSwitch Else Return MsgBox(0, 'Unknown Location', 'IP Address is: ' & $IPaddress) EndIf EndFunc ;==>_IPRule Edited December 4, 2010 by Varian Link to comment Share on other sites More sharing options...
Elephant007 Posted December 4, 2010 Author Share Posted December 4, 2010 As an example_IPRule(@IPAddress1) _IPRule(@IPAddress2) Func _IPRule($IPaddress) $IPArray = StringSplit($IPaddress, '.', 2) If Not IsArray($IPArray) Or UBound($IPArray) <> 4 Then Return MsgBox(0, 'Error', '$IPArray is not an array') If $IPArray[0] = 0 Then Return MsgBox(0, 'ERROR', 'Bad IP Address') If $IPArray[0] = 10 Then Switch $IPArray[1] Case 1 To 100 MsgBox(0, 'Location', 'Location is in the 0 - 100') ;do something else here if you want Case 100 To 200 MsgBox(0, 'Location', 'Location is in the 100 - 200') ;do something else here if you want Case 201 To 255 MsgBox(0, 'Location', 'Location is in the 201 - 255') ;do something else here if you want EndSwitch Else Return MsgBox(0, 'Unknown Location', 'IP Address is: ' & $IPaddress) EndIf EndFunc ;==>_IPRule EDIT...This may be a little better for your needs (to get you started with your logic)Local $IPList[4] = [@IPAddress1,@IPAddress2,@IPAddress3,@IPAddress4] For $Element In $IPList _IPRule($Element) Next Func _IPRule($IPaddress) Local $IPArray = StringSplit($IPaddress, '.', 2) If Not IsArray($IPArray) Or UBound($IPArray) <> 4 Then Return MsgBox(0, 'Error', '$IPArray is not an array') If $IPArray[0] = 0 Then Return MsgBox(0, 'ERROR', 'Bad IP Address') If $IPArray[0] = 10 Then Switch $IPArray[1] Case 1 To 100 MsgBox(0, 'Location', 'Location is in the 0 - 100') ;do something else here if you want Case 100 To 200 MsgBox(0, 'Location', 'Location is in the 100 - 200') ;do something else here if you want Case 201 To 255 MsgBox(0, 'Location', 'Location is in the 201 - 255') ;do something else here if you want EndSwitch Else Return MsgBox(0, 'Unknown Location', 'IP Address is: ' & $IPaddress) EndIf EndFunc ;==>_IPRule Woo Hoo!! You're saying I have some sort of Logic! Well the second script you provided for me can be tweaked to how I need it to be tweaked to, I believe. I can only test it in the domain environment though. I've tweaked it some at home and I can see that, so far, it will work how I need it to work. This is the second time you've helped me with a script and I thank you! Link to comment Share on other sites More sharing options...
Varian Posted December 4, 2010 Share Posted December 4, 2010 (edited) Woo Hoo!! You're saying I have some sort of Logic!Well the second script you provided for me can be tweaked to how I need it to be tweaked to, I believe.I can only test it in the domain environment though. I've tweaked it some at home and I can see that, so far, it will work how I need it to work. This is the second time you've helped me with a script and I thank you!Glad to help!!EDIT...In the 2nd Case statement I should have made it 101 to 200, but you'd have figured that out, right?! Edited December 4, 2010 by Varian Link to comment Share on other sites More sharing options...
Elephant007 Posted December 4, 2010 Author Share Posted December 4, 2010 Glad to help!! EDIT...In the 2nd Case statement I should have made it 101 to 200, but you'd have figured that out, right?! Yes I did, here's how my script turned out and it works GREAT! now I only have to build one installation package.. Local $IPList[4] = [@IPAddress1,@IPAddress2,@IPAddress3,@IPAddress4] For $Element In $IPList _IPRule($Element) Next Func _IPRule($IPaddress) Local $IPArray = StringSplit($IPaddress, ".", 2) If Not IsArray($IPArray) Or UBound($IPArray) <> 4 Then Return MsgBox(0, "Error", "$IPArray is not an array") If $IPArray[0] = 0 Then EndIf If $IPArray[0] = 10 Then Switch $IPArray[1] Case 101, 201, 208 $Name = "Training" Case 103 $Name = "Bonham" Case 104 $Name = "Bowie" Case 150 $Name = "Ward" Case 152 $Name = "Ortiz" EndSwitch If FileExists ( @ProgramFilesDir & "\Ellis\Kids\Ellis Essentials 2.7 Client.msi" ) Then RunWait ( "e28cu\Setup.exe /s /SMS /F1e28cu\upgrade.iss", @WindowsDir, @SW_HIDE ) Else RunWait ( 'Setup.exe /s /SMS /F1' & $Name & '.iss', @WindowsDir, @SW_HIDE ) EndIf EndIf EndFunc Link to comment Share on other sites More sharing options...
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