title: Batch file: Finding IP and opening a program
body: <p>Alright, I'm a bit of a noob when it comes to batch files, so please be gentle :)</p>
  
  <p>I'm writing a batch file that restarts programs. One of the programs should only be opened if the computer has a certain IP address. So the line I'm stuck on, would have to get the IP of the machine (They are set to static IPs) and if it has the right IP, it would open the program. If it doesn't have the right IP, to move on to the next command. I've did a lot of searching around and can't find anything I've been able to get to work. </p>
  
  <p>So this line should: 1. search for the IP 2. If the IP of the machine (for argument sake) is 192.168.1.5 then it should run a certain program. 3. If the IP isn't 192.168.1.5, it will continue on to the next line which closes another program. Any help would be much appreciated! Thank you!</p>
  
  <p><em><strong>Edit</em></strong></p>
  
  <pre><code>setlocal enabledelayedexpansion
  taskkill /f /im "program1.exe"
  for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IPv4 Address"') do (
  set ip=%%a
  set ip=!ip: =!
  goto :BREAK
  )
  :BREAK
  if %ip%==192.168.165.82 (
  C:\Folder\Folder\Folder\program1.exe
  ) else (
  taskkill /f /im "Pro gram 2.exe"
  )
  start "" "C:\Program Files\folder\Pro gram 2.exe"
  taskkill /f /im "program3.exe"
  if exist "C:\Program Files\folder\program3.exe" start "" "C:\Program Files\folder\program3.exe"
  </code></pre>