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 9096577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:53:19+00:00 2026-06-16T23:53:19+00:00

I have a question regarding sniffing packets from a specific client. I am running

  • 0

I have a question regarding sniffing packets from a specific client. I am running a very simple UDP server as follows:

from socket import *

IPv4 = ""
Port = 54345

ServerSock = socket(AF_INET, SOCK_DGRAM) # UDP
ServerSock.bind((IPv4, Port))
print "Socket is ready to receive data.."

while True:
    data, addr = ServerSock.recvfrom(1024) # buffer size is 1024 bytes
    print data

and I intend to capture every packet that comes to the port number(54345) and parse its header values. I think it is doable if the packets are saved to .pcap file and probably use scapy to process them but is it possible to process every packet once it arrives using “socket.recvfrom”?. Thanks

  • 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-16T23:53:20+00:00Added an answer on June 16, 2026 at 11:53 pm

    You’ve already got the data. However, what you’ve got is UDP packets and source addresses; if you want the complete raw packet, with the IPv4 and UDP headers, that’s different.

    On some platforms, you can set a normal UDP socket to IP_HDRINCL, or there are other equivalents. If you do this, each recvfrom will include the headers in the data, so you’ve already got everything you want.

    On other platforms, you can use SOCK_RAW instead of SOCK_DGRAM. What you can do with raw sockets varies dramatically. On many Unix platforms, you can use IPPROTO_UDP with SOCK_RAW, and then bind to a normal UDP address and port, although there may be restrictions, and they’re different on each platform. For example, on OS X, you have to be root to create a raw socket, and you can only bind a raw socket to a single-interface address (meaning no ''/INADDR_ANY/'0.0.0.0'). If you Google for “SOCK_RAW Python” and “SOCK_RAW ” you should be able to find out what you need. (The last example in the sockets module docs shows how to use raw sockets on Windows.)

    Once you’ve got the data, saving it to a pcap file isn’t hard. The format is documented at LibpcapFileFormat at The Wireshark Wiki. If you have any familiarity with the stdlib struct module, it should be easy to figure out how to write this format. Here’s a brief sample:

    pcap_hdr = struct.pack('=IHHiIII',
                           0xa1b2c3d4, # magic number
                           2, 4,       # pcap 2.4 format
                           0,          # UTC timezone for timestamps
                           0,          # "in practice, all tools set it to 0"
                           65535,      # max packet length
                           228)        # LINKTYPE_IPV4, or maybe you want LINKTYPE_RAW
    pcapfile.write(pcap_hdr)
    

    If you don’t want to do that yourself, I don’t have any experience with using libraries to write pcap files, but scapy would be the first place I’d look, then the python-libpcap bindings for libpcap/WinPcap. If none of those work, check around PyPI.

    If all of this sounds beyond you, you probably don’t want to do things this way. Just run your UDP server, and use Wireshark to capture all of the packets sent to it.

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

Sidebar

Related Questions

I am doing coding in linux architecture. I have question regarding socket server and
I have a question regarding threading in Java. In my code, ... client.doSth(); //
I have a question regarding parsing data from Wikipedia for my Android app. I
I have a question regarding calling methods from different threads. Well I am using
I would have question regarding web services. Let's say I have webservice client that
I have a question regarding rendering the KnpMenu Bundle for Symfony2. From I've read,
Hi I have question regarding cin and buffer. I want to make a simple
I have a question regarding specific inclusion of functionality using shared libraries. I have
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have

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.