I am having trouble getting this simple code to display the ip address in between <p>
/</p>
HTML tags.
The code below works, outputting to a text file is ok.
if /i %opt%==1 ipconfig |findstr "IPv4">>"..\LOGS\%NAME%\%serial% %MAC%".txt
The code below is where I would like to embed the CMD code but it just ignores the code or prints in plain text depending on how I modify it; would it need escape characters?
^<td width="38%%" class="table-border-left"^>^<p^>IP Address^</p^>^</td^>
and output to a HTML file:
>> "..\LOGS\NAME%\%serial% %MAC%".html
Any suggestions?
Your question is essentially, 'How do I obtain just the IPv4 Address from ipconfig.exe, and use it'?
batch-file example using your ipconfig command, (the result is returned as %%J
):
For /F "Delims=" %%G In ('%SystemRoot%\System32\ipconfig.exe
^| %SystemRoot%\System32\findstr.exe /R /C:"^[ ][ ]*IPv4[ ]"'
) Do For /F "Tokens=1,* Delims=:" %%H In ("%%G") Do For /F %%J In ("%%I"
) Do Echo ^<td width="38%%" class="table-border-left"^>^<p^>%%J^</p^>^</td^>
The above is a single line command, which has been split to work without modification, but remain readable. If you want to run it as a single line then it would look like this:
For /F "Delims=" %%G In ('%SystemRoot%\System32\ipconfig.exe ^| %SystemRoot%\System32\findstr.exe /R /C:"^[ ][ ]*IPv4[ ]"') Do For /F "Tokens=1,* Delims=:" %%H In ("%%G") Do For /F %%J In ("%%I") Do Echo ^<td width="38%%" class="table-border-left"^>^<p^>%%J^</p^>^</td^>
Please note that there may be more than one adapter bound to TCP/IP, so you may see more than one result returned