search

Home  >  Q&A  >  body text

python - How to do port monitoring.

windwos, how to do it like phpstudy. If the port is killed, the light will turn red... If the port is monitored, it will turn green... And it is real-time... Please give me some guidance...

为情所困为情所困2728 days ago1059

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-30 09:56:51

    I have never done a real-time one, but I want to make a semi-real-time one. Use the socket to communicate with the target port every 30 seconds. If the communication fails, it will alarm.

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((conn_ip,conn_port))
        logging.info('IP:'+str(conn_ip)+',PORT:'+str(conn_port)+',connect successful')
    except Exception as e:
        logging.warning('IP:'+str(conn_ip)+',PORT:'+str(conn_port)+',connect failed!!check the client!!')
        send_msg(conn_ip,conn_port) #发送报警短信
    finally:
        s.close()
    

    This is a rough version, that’s what it means...I don’t know if it will be helpful to you

    reply
    0
  • Cancelreply