监控端口的几个主要Keys: net.tcp.listen[port] Checks if this port is in LISTEN state. 0 - it is not, 1 - it is in LISTEN state. 监控TCP端口是否监听 net.tcp.port[<ip>,port] Check, if it is possible to make TCP connection to the port number. 0 - cannot connect, 1 - can
# coding=utf-8 import sys import socket import re 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, por