Script Ping (Host To IP) to the variable.

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 www.google.com count=2]
:put $PingResult
:log info $PingResult

result
:log info “2”

How to do that resulted in the IP:
:log info “213.241.87.25”

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.

ping msn.com
:put [/ip dns cache get value-name=address [find name="msn.com"]];

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. http://www.msn.com and msn.com are two separate DNS entries. So each command has to match.

there are some ways to do it.
you can use resolve command, something like this
{
local host1 [resolve google.com]
put $host1 }or
{
local host1 [resolve google.com]
log error $host1 }