Solved How to read ip from a text file and store it in a variable

September 20, 2015 at 01:47:33
Specs: Windows
Hello,

With the following command i can get the current IP:
nslookup myip.opendns.com resolver1.opendns.com

It will output this:

Server: resolver1.opendns.com
Address: 12.223.322.3

Non-authoritative anwser:
Name: myip.opendns.com
Address: 123.44.55.3

Where the last line of the output is the current IP. So that would be 123.44.55.3
I want that address to be stored into a variable so I can use it in a batch script.

I want to use that variable with this command:
route add <IP> mask 255.255.255.255 192.168.x.x metric 1

Where <IP> would be the variable with 123.44.55.3.

How can i accomplish this with a simple batch script?

Thank you for your help.


See More: How to read ip from a text file and store it in a variable

Report •

#1
September 20, 2015 at 02:58:54
✔ Best Answer

@echo off
for /F "tokens=2" %%i in ('nslookup myip.opendns.com resolver1.opendns.com') do (
set IPadd=%%i
)
route add %IPadd% mask 255.255.255.255 192.168.x.x metric 1


Report •

#2
September 20, 2015 at 03:26:04
Thank you very much!
It does exactly what I want it to do!

[SOLVED]


Report •
Related Solutions


Ask Question