WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

TCPIP and IP Address

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Run Winipcfg, Write Output to a File, then Parse the File for IP Address

Keywords: 

This script searches the Winipcfg.txt for the first occurrence of the string "Default Gateway" after "IP Address. . . . . . . . . : 172". It then extracts the IP Address and prints it out.
; Run Winipcfg and write output to txt.  Will overwrite file each time.
; Stores txt in same location as this script
RunWait("winipcfg.exe","/all /batch winipcfg.txt")

fs = FileSize( "%windir%winipcfg.txt" )
binbuf = BinaryAlloc( fs )
BinaryRead( binbuf, "%windir%winipcfg.txt" )
;
; Search for first occurrence of "IP Address. . . . . . . . . : 172." 
a = BinaryIndex( binbuf, 0, "IP Address. . . . . . . . . : 172", @FWDSCAN )  
;
; Search for first occurrence of "Default Gateway."
ipAddr = BinaryIndex( binbuf, a, "Default Gateway", @FWDSCAN)
;
; Single out the actual Default Gateway from the line which contains "Default Gateway" string,
; skipping over the redundant first 32 characters.
linebegin = BinaryIndex( binbuf, ipAddr, @CRLF, @BACKSCAN) + 32
;
; Search for the end of the line which contains the "Default Gateway" string.
lineend = BinaryIndex( binbuf, ipAddr, @CRLF, @FWDSCAN)
linelen = lineend-linebegin+1
;
; Extract the line with "Default Gateway" string.
linedata=BinaryPeekStr(binbuf, linebegin, linelen)
binbuf=BinaryFree(binbuf)
Message("The Default Gateway is:",  linedata)

Article ID:   W14740
Filename:   Run Winipcfg Write Output Parse Output.txt
File Created: 2001:03:13:16:38:12
Last Updated: 2001:03:13:16:38:12