Community discussions

MikroTik App
just joined
Topic Author
Posts: 4
Joined: Sat Oct 11, 2014 2:48 pm

Script Ping (Host To IP) to the variable.

Sat Oct 11, 2014 2:58 pm

Hi, I do not know how to write a script. Please help.
I would like to use ping to the domain.
Then assign the host IP to a variable.
:local PingResult

:set PingResult [ping count=2]
:put $PingResult
:log info $PingResult
:log info "2"

How to do that resulted in the IP:
:log info ""
Posts: 27
Joined: Tue Apr 19, 2011 10:12 pm

Re: Script Ping (Host To IP) to the variable.

Tue Oct 14, 2014 12:10 am

google is probably not the best example, since it returns multiple ips. It has many servers that can respond.

I used msn because it returned one address.
:put [/ip dns cache get value-name=address [find name=""]];  
First ping the domain you wish to find.
Then extract the IP from the DNS cache.

Make sure that you use the same exact domain in each command. and are two separate DNS entries. So each command has to match.
User avatar
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Script Ping (Host To IP) to the variable.

Tue Oct 14, 2014 1:11 am

there are some ways to do it.
you can use resolve command, something like this

ros code

local host1 [resolve]
put $host1 }

ros code

local host1 [resolve]
log error $host1 }

Who is online

Users browsing this forum: regae and 18 guests