cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1996
Views
0
Helpful
2
Replies

EEM or TCL script to test for open port

Hello all,

Has anyone had success with developing a script to test for an open port? For example, I'd like to use my router to ocasionally check if port 3389 is open on 192.168.1.1. I've scripted a few tests already, but this is the one thing that I haven't been very successful in completing. 

 

Any and all suggestions / support are welcome. Thanks in advance to anyone who's able to assist.

 

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

Here's some simple EEM Tcl code that should work:

 

::cisco::eem::event_register_timer watchdog time 3600

 

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

 

if { [catch {socket 192.168.1.1 3389} result] } {

    action_syslog msg "tcp/3389 on 192.168.1.1 is no longer open"

}

 

set fd $result

 

close $fd

 

action_syslog msg "tcp/3389 on 192.168.1.1 is open"

View solution in original post

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

Here's some simple EEM Tcl code that should work:

 

::cisco::eem::event_register_timer watchdog time 3600

 

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

 

if { [catch {socket 192.168.1.1 3389} result] } {

    action_syslog msg "tcp/3389 on 192.168.1.1 is no longer open"

}

 

set fd $result

 

close $fd

 

action_syslog msg "tcp/3389 on 192.168.1.1 is open"

Joseph,

As always, thank you very much for your effort and assistance on this.

 

I ran the following in tclsh and it worked great.

catch {socket 74.125.225.83 443} result

 

I had omitted another peice of the puzzle, but I was able to find the solution. I needed to source the socket request from a certain interface. Here is what I found:

catch {socket -myaddr 192.168.1.1 74.125.225.83 443} result

 

Thanks again!

Review Cisco Networking for a $25 gift card