Cadzow Knowledgebase


Welcome
Contact Us
Professional
Services

Consulting
Knowledgebase/
Site Search

Remote Support

Print Friendly

Scripting: Determine Workstation's IP Address

The following script determines the workstation's IP address.

@echo off
ping %COMPUTERNAME% -4 -n 1 | find /i "ping statistics" > %TEMP%\results.txt
for /f "tokens=1-7,* delims=:. " %%a in ('type %TEMP%\results.txt') do set IP1=%%d& set IP2=%%e& set IP3=%%f& set IP4=%%g
del %TEMP%\results.txt
echo Your IP is %IP1%.%IP2%.%IP3%.%IP4%

How It Works

Output from the PING command is piped into FIND to return only the results line, which is output to a text file. The contents of the text file is then fed into FOR which extracts the 4th (%%d), 5th (%%e), 6th (%%f) and 7th (%%g) parameters. These are then stored in environment variables so they are available to any further commands.

Advantages

  • Uses native Windows commands.

  • Works on Windows 2000 and above (not tested Windows NT).

  • Returns the most likely usable IP address the workstation is accessible on.

  • Does not require local administrator or elevated privileges.

Disadvantages

  • Relies on current network allowing the machine to ping its own name.

  • May return wifi address in preference to ethernet address.

  • Only supports IPv4.

Copyright © 1996-2023 Cadzow TECH Pty. Ltd. All rights reserved.
Information and prices contained in this website may change without notice. Terms of use.


Question/comment about this page? Please email webguru@cadzow.com.au