0

I have a problem with my Batch file. In my file, i want to get the IP address of my machine as a variable.

Im running Windows Server 2003 R2

So, this is what i tried :

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IP"') do set ip==%%b
set ipAddress=%ip:~1%
echo IP Address : %ipAddress%

This work well on my others machines but not on this one because i have multiple ip address in ipconfig.

When i write "ipconfig", this is what i got :

Ethernet adapter Local Are Connection 4:
IP Address .... : 10.98.xx.xx

...

Ethernet adapter Local Area Connection 3 :
IP Address .... : 172.22.xx.xx

What i want to do is to have 10.98.xx.xx ip in my variable but with my command what i got is 172.22.xx.xx

Thank you in advance and excuse my bad english !

Raskm
  • 13
  • 1
  • 4
  • Possible duplicate of [How do I do set a variable in Windows command line to an IP?](https://stackoverflow.com/questions/7575119/how-do-i-do-set-a-variable-in-windows-command-line-to-an-ip) – phuclv Feb 27 '18 at 10:54
  • [How do I do set a variable in Windows command line to an IP?](https://stackoverflow.com/q/7575119/995714), [Store IP address in variable](https://stackoverflow.com/q/16815879/995714) [How do I get the IP address into a batch-file variable?](https://stackoverflow.com/q/5898763/995714), another solution is [wmic](https://stackoverflow.com/q/27160042/995714) – phuclv Feb 27 '18 at 10:56

3 Answers3

0

Sadly, you've over-censored and retyped the ipconfig output.

I'd suggest

('ipconfig^|find "IP"^|find ": 10."') 

to select that entry that contains : 10.

Magoo
  • 77,302
  • 8
  • 62
  • 84
0
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip==%%b
set ipAddress=%ip:~1%
echo IP Address : %ipAddress%
John Doe
  • 9
  • 3
0

This is simple batch file works. I made this for our EU to be able to tell me their IP.

cd /

ipconfig | find /i "IPv4"

Pause