from socket import * def udpsender(): # 1. 創建套接字 udpSocket = socket(AF_INET, SOCK_DGRAM) # 2. 准備接收方的地址 sendAddr = ('127.0.0.1', 514) # 3. 從鍵盤獲取數據 sendData = input("請輸入要發送的數據:") sendData=sendData.encode() # 4. 發送數據到指定的電腦上 udpSocket.sendto(sendData, sendAddr) # 5. 關閉套接字 udpSocket.close() if __name__ == '__main__': udpsender()
linux shell: echo "hello" > /dev/udp/localhost/10001
工具使用updsender:配置