Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

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.

 

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Here's some simple EEM Tcl

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"

2 REPLIES
Cisco Employee

Here's some simple EEM Tcl

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"

New Member

Joseph,

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!

233
Views
0
Helpful
2
Replies