| 1. |
Solve : Script that executes steps (takes action) if IP address is correct? |
|
Answer» I wrote a script that installs program updates based on a number of criteria including which DATA center the server is located in. However the script doesn't SEEM to determine the data center properly. My 2¢ 10¢ worth I'd say that was worth a couple of dollars at least, SW. 10.44.xxx.xxx should go to proxyon though... Salmontrout, THANK YOU! That did the trick. Was able to test this morning and everything worked as it should. Is it possible to do something like this: If Errorlevel 0 in (ipconfig | findstr "10.64" > NUL) GOTO ? I just refreshed my screen and saw more replies. I'm interested in what Sidewinder posted too. What does Code: [Select]&& do? Thanks again, MJQuote What does && do? Do you want to handle that, SW? Quote Do you want to handle that, SW? Haven't got a clue The symbol && is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is true. Code: [Select]ipconfig | findstr /r " 10\.64\." > nul && goto proxyoff In this case the goto is executed if the findstr instruction is true, meaning the IP pattern (" 10\.64\.") has been found. If you are interested, there is an inverse notation || , which is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is false. Put another way, the && and || operator are errorlevel tests. command1 && command2 this line runs command1 and if the errorlevel from command1 is equal to 0 (zero), then it runs command2. command1 || command2 this line runs command1 and if the errorlevel from command1 is NOT equal to 0 (zero), then it runs command2. (note: "not equal to zero" - not just greater than zero; less than zero also. Some programs return negative errorlevels.) You can do stuff with brackets as well command1 && ( echo no error some other code to execute if there was no error ...etc ) You can combine && and || if you do this put the && test first. command1 && (echo no error) || (echo an error) command1 && ( echo no error echo That's right, no error ) || ( echo an error echo Yup, an error ) In fact with a little thought you can do away with GOTOs and labels. http://judago.webs.com/batchoperators.htmnice pageI use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets @echo off set mycommand=netsh interface ip show addresses "Local Area Connection" for /f "tokens=1-3 delims= " %%A in ('%mycommand% ^| find "IP Address:"') do set hostIP=%%C for /f "tokens=1-4 delims=." %%A in ("%hostIP%") do set first2octets=%%A.%%B if "%first2octets%"=="10.64" goto Proxyoff if "%first2octets%"=="10.14" goto Proxyoff if "%first2octets%"=="10.44" goto Proxyon This is fantastic! Excellent information. Thank you everyone!Quote from: Salmon Trout on May 22, 2013, 12:26:31 PM I use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets That relies on the network adapter name and in my case it gives the Virtualbox IP address, and not my internet connection. If the OP wants to get his internet facing IP address then this is one way, relying on an external website to report the information. Code: [Select]@echo off >"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP") >>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://astronomy.comoj.com/ip.php", False) >>"%temp%\ip.vbs" echo objHTTP.Send() >>"%temp%\ip.vbs" echo wscript.echo objHTTP.ResponseText for /f "delims=" %%a in ('cscript /nologo "%temp%\ip.vbs"') do ( if not defined ip set ip=%%a ) echo %ip% pause |
|