Printer FriendlyEmail Article Link

Spirent TestCenter-Automation: How to capture the packets using python script?

Environment/Versions
  • Spirent TestCenter
  • Python
Answer

Below is the code snippet to capture a received stream and then save to pcap

    # Create a capture object. Automatically created and start capture
    hCapture = stc.get(<port handle>, "children-capture")  #<port handle means the handle of the port on which capture needs to be performed.
    stc.config(hCapture, mode="REGULAR_MODE", srcMode="TX_RX_MODE")
    stc.perform("CaptureStart", captureProxyId=hCapture)
 
    from time import gmtime, strftime
    print(strftime("%Y-%m-%d %H:%M:%S", gmtime()), " Retrieving Captured frames...")
 
    stc.perform("CaptureStop", captureProxyId=hCapture)
 
    # Save captured frames to a file.
    stc.perform("CaptureDataSave", captureProxyId=hCapture, FileName="capture.pcap", FileNameFormat="PCAP", IsScap="FALSE")
 
    print("Captured frames:\t", stc.get(hCapture, "PktCount"))


Product : Automation,API,Spirent TestCenter,Packet Captures