if / else in telnet

Hey guys, i need script which checks specific ip’s port to see if it open or not and if it open then do nothing if its closed then run another specific script.

i made this but it does not work

:local telnetOutput [/system telnet 192.168.7.25 80]
:if ($telnetOutput = "") do={
    :log info "Telnet connection to port 80 on 192.168.7.25 failed. Executing script script2..."
    /system script run script2
    :log info "Script script2 executed."
} else={
    :log info "Telnet connection to port 80 on 192.168.7.25 successful. No action required."
}

could someone help me please?

Will not work since the output are sent to a the console and not to a variable.

Test this: (cut & past to a terminal window)

{
:local test [/system telnet  192.168.7.25 80]
:put "Text should come after this"
:put "==========================="
:put $test
}
  1. Text are not written to the variable test
  2. For my web server it takes 30 seconds for the time out to come so script des continue.

You may be able to do some with the SSH command, since it supports using output-to-file=, but not sure how.

not working (( this was my last script

:local test [/system telnet 192.168.25.7 80]
:put "Text should come after this"
:put "==========================="
:put $test
:if ($test = "") do={
    /system script run ping_test_me
} else={
    :log info "Telnet connection to port 80 on 192.168.25.7 successful. No action required."
}

If you did read what I did write: Will not work since the output are sent to a the console and not to a variable.
The post was just to show that nothing was stored in the variable…

I suggested, it may work with SSH, but I have not tested it, so its just more of some to try.

You want create a port scanner or test if http service is up on one server?

i want to check if specific port is up or down on remote server