#!/usr/bin/pythonimport socketimport reimport sysdef check_server(address,port):s = socket.socket()print "Attempting to connect to %s on port %s" % (address,port)try:s.connect((address,port))print "Connected to %s on port %s" % (address,port)return Trueexcept socket.error,e:print "Connected to %s on port %s failed: %s" % (address,port,e)return Falseif __name__ == '__main__':from optparse import OptionParserparser = OptionParser()parser.add_option("-a","--address",dest="address",default='localhost',help="ADDRESS for server",metavar="ADDRESS")parser.add_option("-p","--port",dest="port",type="int",default=80,help="PORT for server",metavar="PORT")(options,args) = parser.parse_args()print 'options:%s, args:%s' % (options,args)check = check_server(options.address,options.port)print 'check_server returned %s' % checksys.exit(not check)