save IP address

  • Thread starter Thread starter SHULTZ
  • Start date Start date
S

SHULTZ

hi all
I want to generate a batch file that save a
IP address to a variable.
Whit the command : ipconfig |find "Indirizzo"
I have this :
Indirizzo IP. . . . . . . . . . . . . : xxx.xxx.xxx.xxx


I use this script to put the IP address in a variable but
not run very well:

::version a) :

@echo off
for /f "tokens=2 delims=:" %a in ('ipconfig ^|find "Indirizzo IP" /i')
do
@echo IP Address is %a

::version b):

@echo off
ipconfig |find "Indirizzo" >ip.txt
for /f "tokens=2 delims=:" %a ip.txt do
@echo IP Address is %a

Both the versions not run
Where is my errors?
thanks.
 
SHULTZ said:
hi all
I want to generate a batch file that save a
IP address to a variable.
Whit the command : ipconfig |find "Indirizzo"
I have this :
Indirizzo IP. . . . . . . . . . . . . : xxx.xxx.xxx.xxx


I use this script to put the IP address in a variable but
not run very well:

::version a) :

@echo off
for /f "tokens=2 delims=:" %a in ('ipconfig ^|find "Indirizzo IP" /i')
do
@echo IP Address is %a

::version b):

@echo off
ipconfig |find "Indirizzo" >ip.txt
for /f "tokens=2 delims=:" %a ip.txt do
@echo IP Address is %a

Both the versions not run
Where is my errors?
thanks.

Double the percent signs, e.g., '%a' becomes '%%a'.
 
SHULTZ said:
Phil Robyn



error syntax

:(

Also, make sure the 'for /f ...' command ending with '@echo ...' is
formatted either as shown below or all as a single line, not two
separate lines as in your original post:

for /f "tokens=2 delims=:" %%a in (
'ipconfig ^|find "Indirizzo IP" /i'
) do @echo %%a
 
Phil Robyn said:
Also, make sure the 'for /f ...' command ending with '@echo ...' is
formatted either as shown below or all as a single line, not two
separate lines as in your original post:

for /f "tokens=2 delims=:" %%a in (
'ipconfig ^|find "Indirizzo IP" /i'
) do @echo %%a

OK, now work fine.
thanks too much.
 
Phil Robyn said:
Also, make sure the 'for /f ...' command ending with '@echo ...' is
formatted either as shown below or all as a single line, not two
separate lines as in your original post:

for /f "tokens=2 delims=:" %%a in (
'ipconfig ^|find "Indirizzo IP" /i'
) do @echo %%a

It's possible to pass a
variable %%a to any other commands?
Examples:

findstr "%%a" ip.txt
this command search the ip "xxx.xxx.xxx.xxx" in a file ip.txt
but not run ?
What can I do?

bye
 
SHULTZ said:
It's possible to pass a variable %%a to any other commands?
Hi

Change
) do @echo %%a
to
) do set IP=%%a

Then you can just use the environment variable %IP% as you see
fit later in the script, e.g. like this:

myprogram.exe %IP%
 
Torgeir Bakken (MVP) said:
Hi

Change
) do @echo %%a
to
) do set IP=%%a

Then you can just use the environment variable %IP% as you see
fit later in the script, e.g. like this:

myprogram.exe %IP%

Thanks!
Work very well!
 
I copied and pasted the code as shown plus;

@echo off
for /f "tokens=2 delims=:" %%a in (
'ipconfig ^|find "Indirizzo IP" /i'
) do @echo %%a
pause

but it doesn't do anything except ask me to press any key.
I also need to pass it to a variable for later use.
I'm actually creating a utility to find the gateway ('ipconfig |find "gateway" /i')
I found one that got the gatewa and put it in a text file, but I need to be able to ping it.
 
Back
Top