Hi, i need help with this code/script. i havent done it, my self, i just want help to undesstand it a bit more
My code/Script:
@echo off
cls
title Internet Protocol (IP)
del IPv4.txt
echo.
for /F "TOKENS=2* DELIMS=:" %%a in ('IPCONFIG ^| find "IPv4"') do for %%b in (%%a) Do set MyIP=%%b
echo ============================= >> IPv4.txt
echo Your PC,s Internet Protocol,s >> IPv4.txt
echo ============================= >> IPv4.txt
echo Internet Protocol version 4: %MyIP% >> IPv4.txt
exit
Its this line i need help with: for /F "TOKENS=2* DELIMS=:" %%a in ('IPCONFIG ^| find "IPv4"') do for %%b in (%%a) Do set MyIP=%%b
The only thing i know is that its trying to find the word "IPv4", and i know that it creates an variable that saves in to an .txt file.
PLZ help me to understand the code =)
Find IPv4, help me understand!?
Moderator: DosItHelp
Re: Find IPv4, help me understand!?
Hi, Joakem
The for command execute the commands between the two ( ) and any output will be assigned to a variable %%a or whatever charachter you put there.
So the command
It has two commands, the first is "IPCONFIG", If you execute that in the command line you will get somthing like that
and this code " ^|" redirect that out put to the command "Find" that search for the word "IPv4" in the previout output.
so if you use this command in the cmd window it should give you the whole line that contain the word "IPv4"
Note, when i run that code it give me nothing, casue as you see in the out put, there is no words like "IPv4"
but if i change that word to "IP" it will give me two lines that has the word "IP".
BUt note that the for loop uses a delimt which is : so the out put for the for loop in a command line should give you just the IP "50.1.1.15" not the whole two lines.
The for command execute the commands between the two ( ) and any output will be assigned to a variable %%a or whatever charachter you put there.
So the command
Code: Select all
IPCONFIG ^| find "IPv4"
It has two commands, the first is "IPCONFIG", If you execute that in the command line you will get somthing like that
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 50.1.1.15
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.10.10.10
and this code " ^|" redirect that out put to the command "Find" that search for the word "IPv4" in the previout output.
so if you use this command in the cmd window
Code: Select all
IPCONFIG |find "IPv4"
Note, when i run that code it give me nothing, casue as you see in the out put, there is no words like "IPv4"
but if i change that word to "IP" it will give me two lines that has the word "IP".
Windows IP Configuration
IP Address. . . . . . . . . . . . : 50.1.1.15
BUt note that the for loop uses a delimt which is : so the out put for the for loop in a command line should give you just the IP "50.1.1.15" not the whole two lines.
Re: Find IPv4, help me understand!?
Tnx for the help i think i get it now