# -*- coding: utf-8 -*- import binascii import re def split_1(data,split_sign): data2=[] for i in data: data3 = i.split(split_sign) for n in data3: n=n.strip() data2.append(n) return data2 def curl_time(data): data = data.encode("gbk") #print "--------------------" #print data #print "--------------------" pattern=re.compile(r"(..:..:..)") time=pattern.findall(data) timetotal=time[-3] print timetotal if timetotal=="--:--:--": timetotal=0 print"**************************" print ("Executive the command expend %s seconeds ."%timetotal) print"**************************" return timetotal def telnet_data(data1,*val): data2=data1.encode('gbk') #data2 = data1.replace(" ","") #data2 = binascii.unhexlify(data1) print data2 data2 = data2.split(" ") #data5=split_1(data2," ") data6=split_1(data2,"{") data=split_1(data6,"}") data4=split_1(data," ") print "-----------" print data4 print "-----------" num=0 if type(val) is tuple: val=list(val) val2=[] for i in val: val1 = i.encode('gbk') #print 11111 #print val1 #print type(val1) val2.append(val1) #val1 = val1.split(",") #for n in val1: #n=n.strip() #val2.append(n) print "-----------" print val2 print "-----------" for i in val2: print i if i in data4: num = data4.index(i) print "%s is ok."%i else: return "not_ok",None curl_time1=curl_time(data1) return "ok",curl_time1 def com_read1(data2): data2 = data2.replace(" ","") data = binascii.unhexlify(data2) #data = data.encode('gbk') #print data #data = data.split(" ") #print data return data def com_read_contain1(data2,val2): data2 = data2.replace(" ","") data = binascii.unhexlify(data2) #data = data.encode('gbk') val2 = val2.encode('gbk') #print data #data = data.split(" ") #print data return data,val2 if __name__ == "__main__": s = '''% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 277 100 107 100 170 175 279 --:--:-- --:--:-- --:--:-- 279{ "SSID_Index" : "2", "errorCode" : "0", "errorMsg" : "OK", "function" : "setWifiSSIDCommon" }''' a,b=telnet_data(s,'"SSID_Index" : "2",','"errorCode" : "0",') #a,b=com_data(s,'root@OpenWrt:~#') print a,b #c = com_read(s) #print c