如何使用Python发送UDP数据,现在需要测试一个功能的稳定性,需要使用脚本来循环的通过UDP发送数据到测试设备上。
废话不多说,上脚本:文章源自陈学虎-https://chenxuehu.com/article/2022/08/8027.html
import socket import time import sys if len(sys.argv) != 2: print("请输入IP参数") ipAddr = sys.argv[1] #client 发送端 client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) PORT = 9988 server_address = (ipAddr, PORT) while True: print(time.strftime("%Y-%m-%d %H:%M:%S") + " " + ipAddr +":left") str = "81 01 06 01 01 01 01 01 FF" client_socket.sendto(bytes.fromhex(str), server_address) time.sleep(70) print(time.strftime("%Y-%m-%d %H:%M:%S") + " " + ipAddr + ":right") str = "81 01 06 01 01 01 02 02 FF" client_socket.sendto(bytes.fromhex(str), server_address) time.sleep(70)
文章源自陈学虎-https://chenxuehu.com/article/2022/08/8027.html
文章源自陈学虎-https://chenxuehu.com/article/2022/08/8027.html 文章源自陈学虎-https://chenxuehu.com/article/2022/08/8027.html
评论