Community discussions

MikroTik App
 
Angel83
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:55 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"
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

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

Tue Oct 28, 2014 11:07 pm

To log the IP, do this:
:log info [:resolve www.google.com]
I don't need any karma... I have Ιησους Χριστος!
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 1848
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

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

Wed Oct 29, 2014 12:08 am

IMHO better way is to "fix" IP durig test to prevent situation when http://www.google.com could resolve to different IPs
:local PingResult
:local PingIP

:set PingIP [:resolve www.google.com]
:set PingResult [ping $PingIP count=2]
:put $PingResult
:log info $PingIP
Real admins use real keyboards.

Who is online

Users browsing this forum: No registered users and 17 guests