save IP address


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.
 
Ad

Advertisements

P

Phil Robyn

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'.
 
P

Phil Robyn

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
 
S

SHULTZ

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.
 
S

SHULTZ

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
 
Ad

Advertisements

T

Torgeir Bakken \(MVP\)

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%
 
S

SHULTZ

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!
 
Ad

Advertisements

Joined
Oct 13, 2011
Messages
2
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top