Cant get this IPCONFIG command to display between <p></p> HTML tags

237 views Asked by At

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?

2

There are 2 answers

3
Compo On BEST ANSWER

Your question is essentially, 'How do I obtain just the IPv4 Address from ipconfig.exe, and use it'?

example using your 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

0
Reino On

To create valid HTML I'd suggest you use a tool like , instead of fiddling with Batch (and lots of escape characters).

ipconfig | xidel -se "(<td width='38%' class='table-border-left'><p>{extract($raw,'IPv4.+: (.+)',1)}</p></td>)"

Alternatively, instead of piping ipconfig to xidel, you can use system() to call ipconfig from within the query. For proper indentation you can use --output-node-indent.

xidel -se "(<td width='38%' class='table-border-left'><p>{extract(system('ipconfig'),'IPv4.+: (.+)',1)}</p></td>)" --output-node-format=html --output-node-indent