Python Forum
Need Help W/ Simple Packet Capture Code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help W/ Simple Packet Capture Code
#1
Hey all,

I need help writing a code that can capture packets (pcap) from a dedicated port. All I need is for the code to capture the packet, timestamp it using the datetime module, and write it to a pcap or even a text file.

I don't really know how to capture packets though. I am guessing I can use Scapy, PyShark, or PyPcap. I'm just hoping someone else out there knows a good deal about this.


I'm thinking:

time = datetime.datetime.now()
packet = #capture command...
f.write(str(time) + '\n' + str(packet)
Does anyone know the capture command? Can it work like this?

I'm ok with doing a packet capture that saves all the packets to a pcap file for later use, I just need the timestamp to be from the datetime module because I am reading serial data in using this time source.

Thanks for the help!
Reply
#2
do you need it in a python script?
wireshark: https://www.wireshark.org/
is excellent at capturing all network activity
Reply
#3
Larz60+ I have used Wireshark! IT IS very awesome.

However, I DO need to write a python code. I would like to record all my sensors using python.
Reply
#4
you can search through these packages: https://pypi.org/search/?q=packet+capture
or if you want to do it from scratch:
http://www.bitforestinfo.com/2017/01/how...iffer.html
or https://medium.com/python-pandemonium/us...db5217f3d5
or https://www.binarytides.com/python-packe...ode-linux/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sending packet onto dummy network device but receiving echo sabuzaki 2 1,412 Feb-12-2023, 10:31 AM
Last Post: Vadanane
  How to send a HTTP response packet using scapy JeffreyStoner 0 2,627 Apr-18-2022, 05:23 AM
Last Post: JeffreyStoner
  Send UDP packet after bind pacmyc 0 2,603 Mar-11-2021, 10:28 PM
Last Post: pacmyc
  Need Help with creating an IP packet with timestamp field using Scapy RTD 0 3,427 Jun-15-2019, 08:21 PM
Last Post: RTD
  Failed to recieve scapy udp packet SkyAmryBoi 1 3,776 Sep-29-2017, 01:26 PM
Last Post: camp0

Forum Jump:

User Panel Messages

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