Example #1
0
    def check_port(self):
        """Check port."""
        if os.getuid() != 0 and settings.PORT < PortAction.OPEN_PORT_LIMIT:
            raise PortNotAvailableError(
                f'Port {settings.PORT} below {PortAction.OPEN_PORT_LIMIT} is not allowed by current user.')

        connections = psutil.net_connections()
        for connection in connections:
            if connection.status != 'LISTEN':
                continue
            if connection.laddr.port == settings.PORT:
                raise PortNotAvailableError(f'Port {settings.PORT} is not available for MindInsight')
 def check_debugger_port(self):
     """Check if the debugger_port is available"""
     if not settings.ENABLE_DEBUGGER:
         return
     ip = settings.HOST
     debugger_port = settings.DEBUGGER_PORT
     port = settings.PORT
     if debugger_port == port:
         raise PortNotAvailableError(
             "The ports for debugger and web page are both %s,"
             "please use another port as debugger-port." % debugger_port)
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
         s.connect((ip, debugger_port))
         s.shutdown(2)
         raise PortNotAvailableError(
             f'Debugger-port {ip}:{debugger_port} is not available for MindInsight'
         )
     except socket.error:
         return
Example #3
0
 def check_debugger_port(self):
     """Check if the debugger_port is available"""
     if not settings.ENABLE_DEBUGGER:
         return
     ip = settings.HOST
     port = settings.DEBUGGER_PORT
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
         s.connect((ip, int(port)))
         s.shutdown(2)
         raise PortNotAvailableError(
             f'Debugger-port {ip}:{port} is not available for MindInsight')
     except socket.error:
         return