Build a tcpdump like hexadecimal view :param p: a Packet :param dump: define if the result must be printed or returned in a variable :return: a String only when dump=True
(p, dump=False)
| 305 | |
| 306 | @conf.commands.register |
| 307 | def hexdump(p, dump=False): |
| 308 | # type: (Union[Packet, AnyStr], bool) -> Optional[str] |
| 309 | """Build a tcpdump like hexadecimal view |
| 310 | |
| 311 | :param p: a Packet |
| 312 | :param dump: define if the result must be printed or returned in a variable |
| 313 | :return: a String only when dump=True |
| 314 | """ |
| 315 | s = "" |
| 316 | x = bytes_encode(p) |
| 317 | x_len = len(x) |
| 318 | i = 0 |
| 319 | while i < x_len: |
| 320 | s += "%04x " % i |
| 321 | for j in range(16): |
| 322 | if i + j < x_len: |
| 323 | s += "%02X " % orb(x[i + j]) |
| 324 | else: |
| 325 | s += " " |
| 326 | s += " %s\n" % sane(x[i:i + 16], color=True) |
| 327 | i += 16 |
| 328 | # remove trailing \n |
| 329 | s = s[:-1] if s.endswith("\n") else s |
| 330 | if dump: |
| 331 | return s |
| 332 | else: |
| 333 | print(s) |
| 334 | return None |
| 335 | |
| 336 | |
| 337 | @conf.commands.register |
no test coverage detected