Exemple #1
0
 def do_exec(command_str, ssh):
     """Execute command"""
     try:
         utils.check_ssh_injection(command_str.split())
         if command_str is not None and ssh is not None:
             stdin, stdout, stderr = ssh.exec_command(command_str)
             res, err = stdout.read(), stderr.read()
             re = res if res else err
             result = re.decode()
     except paramiko.AuthenticationException as ae:
         LOG.error('doexec Authentication error:{}'.format(ae))
         raise exception.InvalidUsernameOrPassword()
     except Exception as e:
         err = six.text_type(e)
         LOG.error('doexec InvalidUsernameOrPassword error')
         if 'timed out' in err:
             raise exception.SSHConnectTimeout()
         elif 'No authentication methods available' in err \
                 or 'Authentication failed' in err:
             raise exception.InvalidUsernameOrPassword()
         elif 'not a valid RSA private key file' in err:
             raise exception.InvalidPrivateKey()
         else:
             raise exception.SSHException(err)
     return result
Exemple #2
0
 def __receive(self,channel):
     info=[]
     while True :
         try:
             res = channel.recv(1024)
         except Exception as e:
             print (e)
             break
         info.append(re.decode("utf-8"))
         for waitStr in waitList:
             if re.search(waitStr,res):
                 break
     p = "".join(info)
     print(p)
     self.log.info(p)
     return p
            'user-agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
            'x-requested-with': 'XMLHttpRequest'
        }

    def translate(self, word):
        # token=self.sign_token.token
        token = 'b825b3a7cc74b7087a38946ab32c1ba1'
        sign = self.sign_token.sign(word)
        #构造请求数据
        data = {
            'from': 'en',
            'to': 'zh',
            'query': word,
            'transtype': 'realtime',
            'simple_means_flag': 3,
            'sign': sign,
            'token': token
        }
        #response=requests.post(self.url,data=data,headers=self.headers)
        response = self.sign_token.session.post(self.url, data=data)
        return sign, token, response.content


tool = TranslateTool()
for word in ['are']:
    sign, token, re = tool.translate(word)
    re = json.loads(re.decode())
    print(sign)
    print(token)
    print(re)
Exemple #4
0
if __name__ == '__main__':
    import chardet, io, sys
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,
                                  encoding='utf8')  #改变标准输出的默认编码
    #sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')         #改变标准输出的默认编码
    ht = kl_http()
    ht.setheaders('''\
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2
''')
    #ht.setcookies('ankc_admin__uid__=ainiku%3A%7B%22u%22%3A%22MDAwMDAwMDAwMLyQiNbHupWh%22%2C%22p%22%3A%22MDAwMDAwMDAwMLyQiNbHupbdxGRqlcaUqHU%22%7D;')
    #ht.setproxy('','','127.0.0.1:8087')
    #r=ht.posturl(r'http://127.0.0.1/')
    #r=ht.geturl(r'http://1212.ip138.com/ic.asp')
    r = ht.geturl(r'http://ss.ainiku.com/')
    if r:
        re = r.read()  #.decode('gbk').encode('utf8')
        charset = chardet.detect(re)
        chars = charset['encoding']
        print(chars)
        strr = re.decode(chars)
        print(strr)
    url = 'http://dlsw.baidu.com/sw-search-sp/soft/e7/10520/KanKan_V2.7.8.2126_setup.1416995191.exe'
    outdir = "./downs"

    def showjindu(a, b):
        print('callback Downloading %0.3f %%' % (100 * a / b))

    print(ht.downfile(url, outdir, None, showjindu))
    os.system("pause")
Exemple #5
0
def piped_output(cmd):
	ps = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
	re = ps.communicate()[0]
	return re.decode('utf-8')
Exemple #6
0
                os.rename(temfilepath,filepath)
                return filepath
            print(e)
            return None

if __name__ == '__main__':
    import chardet,io,sys
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码
    #sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')         #改变标准输出的默认编码
    ht=kl_http()
    ht.setheaders('''\
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2
''');
    #ht.setcookies('ankc_admin__uid__=ainiku%3A%7B%22u%22%3A%22MDAwMDAwMDAwMLyQiNbHupWh%22%2C%22p%22%3A%22MDAwMDAwMDAwMLyQiNbHupbdxGRqlcaUqHU%22%7D;')
    #ht.setproxy('','','127.0.0.1:8087')
    #r=ht.posturl(r'http://127.0.0.1/')
    #r=ht.geturl(r'http://1212.ip138.com/ic.asp')
    r=ht.geturl(r'http://ss.ainiku.com/')
    if r:
        re=r.read()#.decode('gbk').encode('utf8')
        charset=chardet.detect(re)
        chars=charset['encoding']
        print(chars)
        strr=re.decode(chars)
        print(strr)
    url='http://dlsw.baidu.com/sw-search-sp/soft/e7/10520/KanKan_V2.7.8.2126_setup.1416995191.exe'
    outdir="./downs"
    print(ht.downfile(url,outdir))
    os.system("pause")