Guest User

Untitled

a guest
Mar 29th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import struct
  2.  
  3.  
  4. data = "45 00 00 4e f7 fa 40 00 38 06 9d 33 d4 b6 18 1b c0 a8 00 02 0b 54 b9 a6 fb f9 3c 57 c1 0a 06 c1 80 18 00 e3 " \
  5. "ce 9c 00 00 01 01 08 0a 03 a6 eb 01 00 0b f8 e5 6e 65 74 77 6f 72 6b 20 70 72 6f 67 72 61 6d 6d 69 6e 67 20 " \
  6. "69 73 20 66 75 6e "
  7. data_new = data.replace(" ", "")
  8. protocol = int(data_new[18:20], 16)
  9. print("version:" + str(int(data_new[:1], 16)))
  10. print("sourcePort: " + str(int(data_new[24:26], 16)) + ":" + str(int(data_new[26:28], 16)) + ":" +
  11. str(int(data_new[28:30], 16)) + ":" + str(int(data_new[30:32], 16)))
  12. print("destinationPort: " + str(int(data_new[32:34], 16)) + ":" + str(int(data_new[34:36], 16)) + ":" +
  13. str(int(data_new[36:38], 16)) + ":" + str(int(data_new[38:40], 16)))
  14. if protocol == 6:
  15. print("protocol = TCP")
  16. print("sourcePort: " + str(int(data_new[40:44], 16)))
  17. print("destinationPort:" + str(int(data_new[44:48], 16)))
  18. header = int(data_new[64], 16) * 8
  19. print(bytes.fromhex(data_new[40 + header:]).decode('utf-8'))
  20. else:
  21. print("protocol = UDP")
  22. print("sourcePort: " + str(int(data_new[40:44], 16)))
  23. print("destinationPort:" + str(int(data_new[44:48], 16)))
  24. print(bytes.fromhex(data_new[40 + 16:]).decode('utf-8'))
  25.  
  26.  
  27.  
  28.  
  29. output:
  30.  
  31. version:4
  32. sourcePort: 212:182:24:27
  33. destinationPort: 192:168:0:2
  34. protocol = TCP
  35. sourcePort: 2900
  36. destinationPort:47526
  37. network programming is fun
Advertisement
Add Comment
Please, Sign In to add comment