import socket from socket import AF_PACKET, SOCK_RAW, htons, ntohs from struct import pack, unpack from time import time, sleep import json import hashlib ifindex = 3 s = socket.socket(AF_PACKET, SOCK_RAW, htons(0x88b7)) # mreq = pack('@iHH8s', ifindex, 0, 6, '\xff\x3a\xf6CAN\x00\x00') # s.setsockopt(263, 1, mreq) # (addr, dlc) = unpack('>IB', s.data[:5]) import sys addr = int(sys.argv[1]) data = '' for d in sys.argv[2:]: data += chr(int(d)) dlc = len(data) addr = 0xcc080440 + addr data = pack('>IB', addr, dlc) + data + '\x00' * (3 + 8 - len(data)) src = '\x00\x04\x23\xb6\xde\xe4' dst = '\xff\x3a\xf6CAN' # dst = '\xd2r0ket' proto = 0x88b7 oui = '\x00\x80\x41' subp = 0xaaaa typ = 3 data = pack('6s6sH3sH', dst, src, proto, oui, subp) + data s.sendto(data, ('eth0', 0)) #sleep(0.1) #s.sendto(data, ('bond0.4', 0)) #sleep(0.1) #s.sendto(data, ('bond0.4', 0))