elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Problema con puertos de escucha en Python
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con puertos de escucha en Python  (Leído 3,162 veces)
jojoesyoyo

Desconectado Desconectado

Mensajes: 6



Ver Perfil WWW
Problema con puertos de escucha en Python
« en: 6 Marzo 2006, 04:57 am »

Hola, estoy scribiendo un servidor en python(linux-debian), para un nuevo protocolo inventado por mi (quiero experimentar). El servidor escucha en el puerto 1864, que he verificado que está disponible para uso. Cuando intento conectarme (desde mi misma computadora) al servidor:
Código:
>>> soc.connect(('localhost', 1864))

Esto functiona perfectamente, y tambien el envio y recepcion de mensajes.

Mi problema es cuando intento acceder al mismo servidor desde otra computadora (de la red local):
Código:
>>> soc.connect(('192.168.1.2', 1864)) #192.168.1.2 es mi ip local
Traceback (most recent callback)
  File "<stdin>", line 1, in ?
  File "<string>", line 1, in connect
socket.error: (10061, 'Connection refused')
No sé que pasa. He verificiado en iptables, y todo está aceptado, nada está bloqueado.
Uso un modem para conectar la red local a internet. Tengo Debian-31r0a, mi arquitectura es i386. Mi version de python es 2.3.5 y 2.4.2 (tengo los dos instalados para probar).
La otra computadora de la red local que uso para probar tiene Windows 98 con Python 2.4.2, su ip es 192.168.1.3.
También he probado con gmailftpd.py y smtpd.py, y tengo el mismo problema.
Mi servidor (está basado en gmailftpd.py, de libgmail para python):
usa una clase derivada de asyncore.dispatcher como servidor, y otra clase derivada de asynchat.async_chat como canal (conexion hacia un 'cliente')
Acá posteo la parte del codigo en el que se inicializa el servidor, y tmb en el que se inicia el canal hacia un 'cliente'.
Código:
class NEAIMChannel(asynchat.async_chat):
  """This is only a channel of the NEAIMServer"""
 
  def __init__(self, server, conn, addr):
    """Method that runs when a new NEAIMChannel is created."""
   
    # Run parent's __init__ method.
    asynchat.async_chat.__init__(self, conn)
   
    # Set object constants and variables
    self.__server = server           # NEAIMServer
    self.__conn = conn               # Connection from the addr to NEAIMServer
    self.__addr = addr               # Address of the client
    self.__line = []                 # Buffer for the commands
    self.__fqdn = socket.getfqdn()   # Fully qualified domain name of localhost ??
    self.__peer = conn.getpeername() # Remote endpoint address
    self.__cver = __version__        # Client version, is by default the same as the
                                     # server, the client can change it by sending'VI x.x'
   
    # Print to DEBUGSTREAM the peername
    print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
   
    # Set terminator for the commands (new line is only \n)
    self.set_terminator('\r\n')
   
    # The channel is initialized, add it to the list
    channels.append(self)
   
    # The 'welcome' message (Version Info)
    self.push('VI %s' % __version__)
   
  #
 
  [...]
     
#

class NEAIMServer(asyncore.dispatcher):
  """The real NEAIMServer, it handles all requests and creates NEAIMChannel's"""
 
  def __init__(self, localaddr):
    """Method that runs when a new NEAIMChannel is created."""
   
    # Set object constants and variables
    self._localaddr = localaddr # Local address
   
    # Run parent's __init__ method
    asyncore.dispatcher.__init__(self)
   
    # Create a socket
    self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
   
    # Try to re-use a server port if possible
    self.set_reuse_addr()
    self.bind(localaddr)
    self.listen(5)
   
    # Print to DEBUGSTREAM that the server is started, and the local address and port.
    print >> DEBUGSTREAM, \
          '%s started at %s\n\tLocal addr: %s\n' % (
        self.__class__.__name__, time.ctime(time.time()),
        localaddr)
   
  #
 
  def handle_accept(self):
    """Called when a new client attepts to connect"""
   
    # Accept the connection, get socket for connection and address
    conn, addr = self.accept()
   
    # Print to DEBUGSTREAM that there's an incoming connection, and the info
    print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
   
    # Create a new channel for the connection
    channel = NEAIMChannel(self, conn, addr)
       
  #
 
#

# Si estamos en __main__
if __name__ == '__main__':

  # Set DEBUGSTREAM
  DEBUGSTREAM = sys.stderr
 
  # Create server
  proxy = NEAIMServer(('127.0.0.1', 1864))
 
  # Create channels array
  channels = []
 
  # Do a infinite loop listening
  try:
      asyncore.loop()
  except KeyboardInterrupt:
      pass

Por si acaso, también tengo un servidor web (apache) instalado en mi computadora, y funciona perfectamente.

Gracias de antemano a los que me respondan...


« Última modificación: 6 Marzo 2006, 15:13 pm por jojoesyoyo » En línea

Joseph
En la programación y en los programas de Codigo Abierto no hay nada imposible, solo difícil.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
problema con python y gtk
Scripting
Belial & Grimoire 1 2,012 Último mensaje 26 Diciembre 2010, 06:05 am
por leogtz
[Python] Scaner de Puertos
Scripting
Exe U. 0 2,356 Último mensaje 17 Enero 2011, 11:08 am
por Exe U.
Problema con python y len
Scripting
eagle17 1 2,422 Último mensaje 5 Mayo 2011, 17:54 pm
por eagle17
Problema en Python
Scripting
WaAYa HaCK 6 5,563 Último mensaje 20 Mayo 2011, 03:39 am
por criskapunk
Problema con microfono, se escucha lento.
Windows
ranslsad 8 9,801 Último mensaje 6 Junio 2012, 21:19 pm
por Randomize
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines