0

If I run the following command on my windows 7 system (where cable is the name of my network adapter)

netsh interface ip show ipaddresses cable

I get the following result:

Address 10.17.179.17 Parameters
---------------------------------------------------------
Interface Luid     : Cable
Scope Id           : 0.0
Valid Lifetime     : 22h46m12s
Preferred Lifetime : 22h46m12s
DAD State          : Deprecated
Address Type       : Dhcp
Skip as Source     : false

For this section of my batch file I only care about getting the IP address (in this example 10.17.179.17) into a variable for later use. The IP address changes everyday or so, so that is why I require a variable.

so effectively I want the result of:

@SET IPaddyVariableName=10.17.179.17
@SET IPaddyVariableName= <some batch file code I need help with as 10.17.179.17 is hardcoded>

Please help me get 10.17.179.17 (which obviously changes) into a variable? Once it's in a variable I'm sorted. Thanks all!

2

1 Answer 1

0

My connection is named Local Area Connection...

for /f "tokens=2 delims= " %%a in ('netsh interface ip show ipaddresses "Local Area Connection" ^| findstr /r "Address[\s]*[^\s]*[\s]*Parameters"') do @set IPaddyVariableName=%%a

echo.
echo %IPaddyVariableName%
echo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .