Extreme Networks Sentriant AG Software User's Manual page 333

Hide thumbs Also See for Sentriant AG:
Table of Contents

Advertisement

Figure 180: checkOpenPorts.py script (continued)
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:
except:
Sentriant AG Software Users Guide, Version 5.3
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
s.close()
if debug:
print "Connected to "+hp+". Port open!"
#
# Add the port to our list of open ports for use later
#
portsOpen += str(p) + ","
if s is not None:
try:
s.close()
except:
pass
System Administration
333

Advertisement

Table of Contents
loading

This manual is also suitable for:

Sentriant ag 5.3

Table of Contents