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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:58+00:00 2026-06-17T14:20:58+00:00

I spend the whole day waiting for a loop to exit without hope!. I

  • 0

I spend the whole day waiting for a loop to exit without hope!. I know that python is not so efficient when it comes to performance as such I would really appreciate any speed-up suggestions to my problem.

I have captured a large number of packets (around 500,000) using wireshark and saved them to .pcap file. After that I read the packets from the saved file by using Scapy rdpcap() function and then I accessed each packet in a loop to extract the source IP Address. My code is as follows:

from scaly.all import *

srcList =[]
Packets = rdpcap("pcapfile")

for pkt in Packets:
    src = Packets[Packets.index(pkt)][1].src
    srcList.append(src)

Note: I have done some digging and I found that Cython is used to speed-up nested loop, but honestly I have no idea how to use that in my case. any insight would be great

  • 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-17T14:20:59+00:00Added an answer on June 17, 2026 at 2:20 pm

    If I am not misunderstanding your intention, you can simplify your code, that should also speed it up:

    from scaly.all import *
    
    Packets = rdpcap("pcapfile")
    srcList = [pkt[1].src for pkt in Packets]
    

    The difference between this solution and yours can be illustrated with a simple example. As you can see, the second function is more than 10 times faster.

    In [1]: lst = range(100)
    
    In [2]: def f1(lst):
       ...:     out = []
       ...:     for item in lst:
       ...:         out.append(lst[lst.index(item)])
       ...:     return out
    
    In [3]: def f2(lst):
       ...:     return [item for item in lst]
    
    In [4]: %timeit f1(lst)
    1000 loops, best of 3: 221 us per loop
    
    In [5]: %timeit f2(lst)
    100000 loops, best of 3: 9.61 us per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent a whole day on this already without figuring it out. I'm hoping
I spend almost whole day trying to render simple polygon using opengl 1.1 and
This stupid question spent me a whole day, and I still don't know how
I hope my whole day trouble will at least be over by now. I
I have spent the whole day trying to make a script which on submit
I've spend the whole morning on this and I am absolutely stumped. I have
I've spent whole day on this problem and still have no idea how to
I am getting 500 Internal error with Apache and FastCGI. Spent the whole day
I have spent the whole day trying to make my application use threads but
Good day everyone. I spent a whole day looking for an answer to my

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.