def listernerController (clientsocket):
  buff = True
  BUFFER_SIZE = 1024
  client_info = clientsocket[0].recv (BUFFER_SIZE)
  while buff != None:
    buff = clientsocket[0].recv (BUFFER_SIZE)
    value = toArray (buff, ':')
    if value[0] == 'message':
        print (client_info + " says: " + value[1])
        broadcast ('Client '+client_info+' says: '+value[1])
    elif value[0] == 'command':
        if value[1] != 'exit':
            print ('Executing '+ value[1]+" for client: "+client_info)
            broadcast (popen (value[1]).read())
        else: break

  clientsocket[0].close()
def client (server, port, debug = False):
  if debug:  print ('Criando socket de cliente...')
  sck = socket (AF_INET, SOCK_STREAM)
  if debug:
      print ("\t\tOK")
      print ('Connectando cliente ao servidor ('+server+', '+str(port)+')' )
  sck.connect ( (server, port) )
  sck.send (sck.getsockname()[0])
  Thread (target=listernerController, args=(sck,)).start ()
  buff = True
  mode = 'message'
  while buff != 'exit':
      buff = raw_input (mode+":")
      aux = toArray (buff, ':')
      if aux[0] == '/switch':
          mode = aux[1]
      elif mode == 'message':
          sck.send (mode+':'+buff)
      elif mode == 'command':
          sck.send (mode+':'+buff)

  if debug: print ('Encerrando cliente...')
Exemple #3
0

from urllib2 import urlopen
from sys import argv, stdout, exit
from os import popen
from str import toArray


if len (argv) < 2:
    print ('\nAdicione as urls para efetuar o download\n')
else:
    for i in range (1, len(argv)):
        try:
            urlcontents=urlopen(argv[i]).read()
            downloaded_file = str(i) + ".down"
            open(downloaded_file, 'w').write(urlcontents)
            print ("\nSalvando arquivo: " + downloaded_file + "\t[" + toArray(popen('du -h ' + downloaded_file).read(), '\n')[0] + "]")
            print ('default', '\n\tFinalizando aplicacao')
        except:
            print ('\nErro ao realizar request!')