Community discussions

MikroTik App
 
Angel83
just joined
Topic Author
Posts: 5
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 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"
 
smileymattj
newbie
Posts: 33
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.
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.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
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 google.com]
put $host1 }
or

ros code

{
local host1 [resolve google.com]
log error $host1 }

Who is online

Users browsing this forum: No registered users and 34 guests