Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Log:
- def __init__(self, date, time, id, custom_data, sn, host):
- self.len = "00"
- self.date = binascii.a2b_hex("0b" + hex(int(date[:4]))[2:].zfill(4) +
- hex(int(date[4:6]))[2:].zfill(2) +
- hex(int(date[6:]))[2:].zfill(2))
- self.time = binascii.a2b_hex("0c" + hex(int(time[:2]))[2:].zfill(2) +
- hex(int(time[2:4]))[2:].zfill(2) +
- hex(int(time[4:6]))[2:].zfill(2))
- self.mode = binascii.a2b_hex("0201")
- self.id = binascii.a2b_hex("05" + hex(int(id))[2:].zfill(4))
- self.module_name = binascii.a2b_hex("0d000000074d6f6e69746f72")
- self.custom_data = binascii.a2b_hex(custom_data)
- self.serial = sn
- self.log_creation_date = 1567092667
- self.host = host
- def get_raw_data(self):
- data = self.date + self.time + self.mode + self.id + self.module_name \
- + self.custom_data
- self.len = binascii.a2b_hex(hex(len(data))[2:].zfill(8))
- return self.len + data
- @classmethod
- def from_config(cls):
- with open("config.json", "r") as file:
- config = json.load(file)
- return cls(config.get("date"), config.get("time"),
- config.get("id"), config.get("custom_data"),
- config.get("sn"), config.get("host"))
- def get_requests(self):
- file = self.get_raw_data()
- h = hashlib.md5(file)
- header = {"Content-type": "application/octet-stream"}
- params = {"SerialNo": self.serial, "ClientId": 12345,
- "logCreationDate": self.log_creation_date,
- "hash": h.hexdigest()}
- requests.post(self.host, params=params, data=file, headers=header)
- if __name__ == "__main__":
- a = Log.from_config()
- f = a.get_requests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement