Python Forum
hex file to binary or pcap to binary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hex file to binary or pcap to binary
#1
I have searched my questions a lot but I couldn't find any solutions, so here's my questions:

I have exported some txt files from pcap files using wireshark. I can also see this output using pkt.hexdump() from scapy module. I want to read the hex part and convert it into binary sequences.
As you can see in the image the file contains other characters such as ASCII that it's not needed. I know how to get an hex input from user or a file containing only hex and convert it, but I don't know how to deal with these files.
I also don't know if it's possible to convert pcap files to binary directly.

hexdec = input("Enter any number in Hexadecimal Format: ")

dec = int(hexdec, 16)
print(hexdec,"in Binary = ", bin(dec))
[Image: IKJGg3N.png]
Reply
#2
you want to take a look at the libpcap library: https://pypi.org/project/libpcap/
github: https://github.com/karpierz/libpcap
docs: https://www.tcpdump.org/papers/bpf-usenix93.pdf

The pcap file is not just one record, but is a protocol of various records explained here: https://github.com/hokiespurs/velodyne-c...CAP-format
Thus to be able to read, you need to extract the various records

Quote:I want to read the hex part and convert it into binary sequences.
I know what you are asking here, but your terminology is incorrect as hex is just one representation of binary data, ASCII is another for printable character format, and does not have values for every binary value.

All binary can be displayed as hex, octal or decimal (and many formats, but not all binary can be displayed as ASCII, as ASCII is for printable characters only).

I think you will probably get what you are looking for with pyshark:
to install: pip install pyshark
github: https://github.com/KimiNewt/pyshark
documentation: Python wrapper for tshark, allowing python packet parsing using wireshark dissectors.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic binary search algorithm - using a while loop Drone4four 1 308 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  How Write Part of a Binary Array? Assembler 1 305 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  Pyserial issues with proper loops and binary jttolleson 16 2,464 Nov-02-2023, 08:39 PM
Last Post: deanhystad
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 555 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  How do I read and write a binary file in Python? blackears 6 6,015 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Binary tree AlexPython 3 930 Dec-07-2022, 06:41 AM
Last Post: ndc85430
  Add one to binary string uwl 2 884 Sep-11-2022, 05:36 PM
Last Post: uwl
  python update binary object (override delivered Object properties) pierre38 4 1,711 May-19-2022, 07:52 AM
Last Post: pierre38
  Hashing an address for binary file Python_help 8 2,566 Nov-04-2021, 06:23 AM
Last Post: ndc85430
  Converting an RGBA image to Grayscale and Binary Joni_Engr 3 4,561 Aug-23-2021, 11:54 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020