> ## Content Index
> Fetch the complete content index at: https://kudithipudi.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# HOW TO : Parse IP Address in Windows Batch File
- URL: https://kudithipudi.org/how-to-parse-ip-address-in-windows-batch-file/
- Published: 2014-06-16T16:04:08.000Z
- Updated: 2014-06-16T16:04:08.000Z
- Description: We had a recent challenge at work which required us to execute different actions based on which office a particular workstation was located in. Since we...
- Author: admin
- Tags: Programming, Technology, Uncategorized, Windows, #wp, #wp-post, #Import 2026-08-23 02:32

We had a recent challenge at work which required us to execute different actions based on which office a particular workstation was located in. Since we have unique network ranges per office, I thought this would be a good variable to use. Just for future reference, here is how we accomplished this in a batch file. The workstations were running Windows 7

```

@ECHO OFF
FOR /f "tokens=3" %%I IN (
‘netsh interface ip show address "Local Area Connection" ^| findstr "IP Address"’
) DO SET ipAddress=%%I
REM "Office 1"
IF NOT x%ipAddress:10.130=%==x%ipAddress% (
ECHO "Office 1" + %ipAddress%
ECHO "do_something_else" )
REM "Office 2"
IF NOT x%ipAddress:10.140=%==x%ipAddress% (
ECHO "Office 2" + %ipAddress%
ECHO "do_something_else" )

```

Details of function used

- **netsh interface ip show address “Local Area Connection”** : With this command we are extracting the IP information of just the LAN port
- **findstr “IP Address”** : returns the line containing “IP Address”
- **IF NOT x%ipAddress:10.130=%==x%ipAddress%** : We are using the substitution function and returning false if the new string doesnt match the original
- **FOR /f “tokens=3”** : Using the functions in the FOR loop to extract the third variable in the matching line