Exemplo n.º 1
0
def readFile(filename):
        try:
                file = open(filename,"rb")
                return file.read()
        except:
                js = "top.connectLog('%s')" % "读取图片文件失败"
                print js
                core.runJs(js)
Exemplo n.º 2
0
def grab():
        try:
                im = ImageGrab.grab()
                im.save("tmp.png",'png')
        except:
                js = "top.connectLog('%s')" % "截图失败"
                print js
                core.runJs(js)
Exemplo n.º 3
0
def sendFile(filename,url):
        try:
                data = readFile(filename)
                tmp = base64.b64encode(data)
                post(url,tmp)
        except:
                js = "top.connectLog('%s')" % "发送文件失败"
                print js
                core.runJs(js)
Exemplo n.º 4
0
def post(url,param):
        try:
                param = ziputils.zip(param)
                ilen = str(len(param))
                req = urllib2.Request(url,param)
                opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
                response = opener.open(req)
                js = "top.connectLog('%s%s')" % ("发送图片完毕,图片大小:",ilen)
                core.runJs(js)
                print js
                return response.read()
        except:
                js = "top.connectLog('%s')" % "无法连接到服务器"
                core.runJs(js)
                print js
Exemplo n.º 5
0
def startSend(data,param):
        j = json.loads(param)
        tmp = base64.b64encode(data)
        tmp = zlib.compress(tmp)
        addr = (j["ip"],int(j["port"]))
        try:
                sendSock = socket(AF_INET,SOCK_STREAM)
                sendSock.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
                sendSock.connect(addr)
                sendSock.send(tmp)
                sendSock.close()
                js = "top.connectLog('%s')" % "发送完毕";
                core.runJs(js)
        except:
                (ErrorType, ErrorValue, ErrorTB) = sys.exc_info()
                (errno, err_msg) = ErrorValue
                error = "连接服务器失败: %s, errno=%d" % (err_msg, errno)
                js = "top.connectLog('%s')" % error;
                core.runJs(js)
Exemplo n.º 6
0
def handleConn(conn):
    try:
        buf = ""
        while True:
            tmp = conn.recv(buf_size)
            if (len(tmp) > 0):
                buf += tmp
            else:
                break

        print len(buf)

        #print tmp

        buf = zlib.decompress(buf)
        core.runJs(callback + "('" + buf + "');")
        info = "接收到图片,大小为:%s" % str(len(buf))
        js = "top.recvLog('%s')" % info
        core.runJs(js)

    except:
        (ErrorType, ErrorValue, ErrorTB) = sys.exc_info()
        (errno, err_msg) = ErrorValue
        error = "程序出现异常: %s, errno=%d" % (err_msg, errno)
        js = "top.recvLog('%s')" % error
        core.runJs(js)
        pass
Exemplo n.º 7
0
 def do_POST(self):
         try:
             ip = self.client_address
             datas = self.rfile.read(int(self.headers['content-length']))
             buf = ziputils.unzip(datas)
             buf = base64.b64decode(buf)
             #buf = datas
         
             #param = "%02d%s%s" % (len(ip[0]),ip[0],buf)
             f = open("./ui/tmp/"+ip[0]+".png","wb")
             f.write(buf)
             #print len(ip[0])
             
             self.wfile.write("1")
             self.wfile.close()
             core.runJs(callback+"('"+ip[0]+"');")
         
             del datas
             del buf
         except:
             self.wfile.write("0")
             self.wfile.close()
             core.runJs("console.log('出现异常');")