Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:27:12+00:00 2026-06-07T18:27:12+00:00

I would like to parse the first two bytes of a packets payload using

  • 0

I would like to parse the first two bytes of a packets payload using Scapy. What would be the best way to accomplish this? Are offset calculations required?

First the payload needs to be parsed though the following will parse the whole PCAP file, is there a more efficient way to obtain the first two bytes of every payload? link:

>>> fp = open("payloads.dat","wb")
>>> def handler(packet):
...     fp.write(str(packet.payload.payload.payload))
...
>>> sniff(offline="capture1.dump",prn=handler,filter="tcp or udp")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:27:13+00:00Added an answer on June 7, 2026 at 6:27 pm

    I see. That looks pretty efficient from here.

    You might try fp.write(str(packet.payload.payload.payload)[:2]) to get just the first 2 bytes.

    You could also do fp.write(str(packet[TCP].payload)[:2]) to skip past all those payloads.

    Alternately, you could define an SSL Packet object, bind it to the appropriate port, then print the SSL layer.

    class SSL(Packet):
      name = "SSL" fields_desc = [ ShortField("firstBytes", None) ]
    
    bind_layers( TCP, SSL, sport=443 )
    bind_layers( TCP, SSL, dport=443 )
    
    def handler(packet):
    ... fp.write(str(packet[SSL]))
    

    …but this seems like overkill.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to parse free-text time intervals like the following, using Python: 1
I have a text file and I would like to parse it using regular
I have an HTML file and i would like to parse through it using
I would like to know the best way of parsing an input where multiple
i would like to have two msg boxes yes/no. The first one for saving
i'm using JSoup to parse a webpage like this , and make it into
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to parse the following text into formatted URLs with anchor tags:
I would like to parse the folder name and file name from passed argument.
I would like to parse the values from aspx pages, both what is passed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.