zoukankan      html  css  js  c++  java
  • python脚本检查TCP端口是否正常

    #!/usr/bin/python
    import socket
    import re
    import sys
    def 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 True
    except socket.error,e:
    print "Connected to %s on port %s failed: %s" % (address,port,e)
    return False
    if __name__ == '__main__':
    from optparse import OptionParser
    parser = 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' % check
    sys.exit(not check)
    
  • 相关阅读:
    定时器
    Vue CLI环境变量
    负数的二进制表示方法
    IDEA指定启动JDK版本
    Windows7安装两个jdk配置
    Bloom Filter 数据结构去重
    新浪微博爬虫参考
    Spring Data JPA
    Spring的JDBC框架
    数据库连接池:Druid
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/7778606.html
Copyright © 2011-2022 走看看