Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. class Log:
  2. def __init__(self, date, time, id, custom_data, sn, host):
  3. self.len = "00"
  4. self.date = binascii.a2b_hex("0b" + hex(int(date[:4]))[2:].zfill(4) +
  5. hex(int(date[4:6]))[2:].zfill(2) +
  6. hex(int(date[6:]))[2:].zfill(2))
  7. self.time = binascii.a2b_hex("0c" + hex(int(time[:2]))[2:].zfill(2) +
  8. hex(int(time[2:4]))[2:].zfill(2) +
  9. hex(int(time[4:6]))[2:].zfill(2))
  10. self.mode = binascii.a2b_hex("0201")
  11. self.id = binascii.a2b_hex("05" + hex(int(id))[2:].zfill(4))
  12. self.module_name = binascii.a2b_hex("0d000000074d6f6e69746f72")
  13. self.custom_data = binascii.a2b_hex(custom_data)
  14. self.serial = sn
  15. self.log_creation_date = 1567092667
  16. self.host = host
  17.  
  18. def get_raw_data(self):
  19.  
  20. data = self.date + self.time + self.mode + self.id + self.module_name \
  21. + self.custom_data
  22. self.len = binascii.a2b_hex(hex(len(data))[2:].zfill(8))
  23. return self.len + data
  24.  
  25. @classmethod
  26. def from_config(cls):
  27. with open("config.json", "r") as file:
  28. config = json.load(file)
  29. return cls(config.get("date"), config.get("time"),
  30. config.get("id"), config.get("custom_data"),
  31. config.get("sn"), config.get("host"))
  32.  
  33. def get_requests(self):
  34. file = self.get_raw_data()
  35. h = hashlib.md5(file)
  36. header = {"Content-type": "application/octet-stream"}
  37. params = {"SerialNo": self.serial, "ClientId": 12345,
  38. "logCreationDate": self.log_creation_date,
  39. "hash": h.hexdigest()}
  40. requests.post(self.host, params=params, data=file, headers=header)
  41.  
  42.  
  43. if __name__ == "__main__":
  44. a = Log.from_config()
  45. f = a.get_requests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement