Community discussions

MikroTik App
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Script for ping from all interfaces

Mon Sep 12, 2022 2:59 pm

Hello.
Can please tell me how correctly ping some resources from all interfaces which i have on a router?
I've created the script, but it doesn't work correctly(
:foreach interface1 in=[/interface print where name~"ether"] do={
 :if ([/ping 8.8.8.8 count=10 interface=$interface1]=0) do={
     :log error "LINK DOWN";
   } else={
     :log info "LINK FINE";
   }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for ping from all interfaces  [SOLVED]

Mon Sep 12, 2022 5:57 pm

with all interfaces, you mean "all true ethernet interfaces"?
/interface
:foreach if in=[find where type="ether"] do={
    :local ifname [get $if name]
    :local result [/ping 8.8.8.8 count=10 interface=$if]
    :if ($result=0) do={
        :log error "Ping on $ifname: ALL FAILED (0/10)"
    } else={
        :if ($result!=10) do={
            :log warning "Ping on $ifname: ONLY SOME ($result/10)"
        } else={
            :log info "Ping on $ifname: ALL OK (10/10)"
        }
    }
}
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Re: Script for ping from all interfaces

Tue Sep 13, 2022 9:14 am

Hello.
Thank you for your reply.
Yes, i mean all ethernet interfaces on the router.
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Re: Script for ping from all interfaces

Tue Sep 13, 2022 9:30 am

And in this case how can hide ping output result?
SEQ HOST SIZE TTL TIME STATUS
0 no route to host
1 no route to host
2 no route to host
3 no route to host
4 no route to host
sent=5 received=0 packet-loss=100%
Leave only the message about FAILED of OK.
I mean when i use :put instead :log
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for ping from all interfaces

Tue Sep 13, 2022 10:29 am

When ping is executed, for default the text go on screen.
Do not exist an option on ping command to do not do that.
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Re: Script for ping from all interfaces

Tue Sep 13, 2022 11:02 am

When ping is executed, for default the text go on screen.
Do not exist an option on ping command to do not do that.
I understand it.
But via a script i can send output result from ping to null and print only the result about FAILED or OK from :put message.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for ping from all interfaces

Tue Sep 13, 2022 11:14 am

how can hide ping output result?

via a script i can send output result from ping to null

Please redefine your question, you contraddice yourself, and I do not understand what you mean.
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Re: Script for ping from all interfaces

Tue Sep 13, 2022 11:43 am

I mean that i want to see only result from my script as massage - FAILED or OK, but without ping output.
For example as in this topic)
viewtopic.php?t=87589
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for ping from all interfaces

Tue Sep 13, 2022 12:36 pm

Well, there is a guy called "rextended" that has already done the script on purpose.
viewtopic.php?t=87589#p861988


:global pingResult -1
/interface
:foreach if in=[find where type="ether"] do={
    :local ifname [get $if name]
    :local jobID [:execute ":set pingResult [:ping 8.8.8.8 count=10 interface=$ifname]"]
    :while ([:len [/system script job find where .id=$jobID] ] > 0) do={
        :delay 1s
    }
    :local result $pingResult
    :if ($result=0) do={
#        :log error "Ping on $ifname: ALL FAILED (0/10)"
:put "FAILED"
    } else={
        :if ($result!=10) do={
#            :log warning "Ping on $ifname: ONLY SOME ($result/10)"
        } else={
#            :log info "Ping on $ifname: ALL OK (10/10)"
:put "OK"
        }
    }
}


Ok, FAILED and OK only.... but 1 successfully ping over 10 is OK for you??? :roll:
 
perrfect
just joined
Topic Author
Posts: 6
Joined: Mon Sep 12, 2022 2:54 pm

Re: Script for ping from all interfaces

Tue Sep 13, 2022 4:27 pm

Yes, one successfully ping is ok for me.
Thank you so much

Who is online

Users browsing this forum: No registered users and 3 guests