Extreme Networks AG200 User Manual page 317

Version 5.0
Table of Contents

Advertisement

Figure 157: checkOpenPorts.py script (continued)
try:
ports = []
if self.inputParams.has_key("ports_not_allowed"):
ports = self.inputParams["ports_not_allowed"].split(",")
else:
# No ports not allowed, pass
return(self.doReturn(returnHash))
if debug:
print "Checking ports " + str(ports) + " on host " +
self.session.host()
#
# Do your test here. Modify the returnHash accordingly.
#
portsOpen = ""
#
# Use a Python socket to connect directly to the target host
#
import socket
for p in ports:
hp = self.session.host()+":"+str(p)
s = None
try:
Sentriant AG Users' Guide, Version 5.0
if debug:
print "Connecting to " + hp
#
# Try to open the port. Throws an exception if connection
# is refused or times out (set timeout to 5 seconds).
#
# Note that Sentriant AG uses a restricted Python socket
# library that doesn't allow connections to arbitrary
# hosts.
Normally, the first element of the tuple passed
# to socket.connect() is the IP or hostname; in SA, you
# must pass the Session object form which the socket
# object will get the target host IP/name.
#
s = socket.socket()
s.settimeout(5)
s.connect((self.session, int(p)))
# Uh oh, no exception. The port was open
System Administration
317

Advertisement

Table of Contents
loading

This manual is also suitable for:

Sentriant ag

Table of Contents