Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- 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 " \
- "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 " \
- "69 73 20 66 75 6e "
- data_new = data.replace(" ", "")
- protocol = int(data_new[18:20], 16)
- print("version:" + str(int(data_new[:1], 16)))
- print("sourcePort: " + str(int(data_new[24:26], 16)) + ":" + str(int(data_new[26:28], 16)) + ":" +
- str(int(data_new[28:30], 16)) + ":" + str(int(data_new[30:32], 16)))
- print("destinationPort: " + str(int(data_new[32:34], 16)) + ":" + str(int(data_new[34:36], 16)) + ":" +
- str(int(data_new[36:38], 16)) + ":" + str(int(data_new[38:40], 16)))
- if protocol == 6:
- print("protocol = TCP")
- print("sourcePort: " + str(int(data_new[40:44], 16)))
- print("destinationPort:" + str(int(data_new[44:48], 16)))
- header = int(data_new[64], 16) * 8
- print(bytes.fromhex(data_new[40 + header:]).decode('utf-8'))
- else:
- print("protocol = UDP")
- print("sourcePort: " + str(int(data_new[40:44], 16)))
- print("destinationPort:" + str(int(data_new[44:48], 16)))
- print(bytes.fromhex(data_new[40 + 16:]).decode('utf-8'))
- output:
- version:4
- sourcePort: 212:182:24:27
- destinationPort: 192:168:0:2
- protocol = TCP
- sourcePort: 2900
- destinationPort:47526
- network programming is fun
Advertisement
Add Comment
Please, Sign In to add comment