Jump to content
Sign in to follow this  

Check telnet connection

Recommended Posts

Hi everyone... I try to do a script that check vía telnet if a port is open, this script needs to execute every 5 minutes and if in the third attempt the script couldn't connect write a log file to capture with a monitoreing tool.

Thanks in advance.

Share this post

Link to post
Share on other sites

Well, I use an example in a topic and Helpfile, but the most important is to do three attemps before the ERROR writes the file.

Somebody know a way to do it?

Here is what I've got:

$g_IP = ""

$g_port = "3389"

; Start The TCP Services



; Connect to a Listening "SOCKET"


$log = FileOpen("c:\connect.log" , 2)

$socket = TCPConnect($g_IP, $g_port)

If $socket = -1 Then

FileWrite($log, "ERROR")


FileWrite($log, "OK")

TCPShutdown ()




Share this post

Link to post
Share on other sites

I ran into this a while back, and took the following approach:

1) Download PORTQRY from Microsoft.

2) Download _RunReadStd() -- lovely UDF available on the forum.

3) Use 1, 2 to write a function like: _TcpPortTest($ip,$port)

essentially, you formulate your portqry request, then execute the command and parse the results.

Eliminates the hassle / overhead of dealing directly w/ the sockets.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post

Link to post
Share on other sites

Thanks for the reply and the PORTQRY...

The problem is that we aren't the server administrator and we are unable to install software, the only way to do the test is with a script.

We are trying skip add the script Microsoft scheduler to run it.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...