1

Wireshark is crashing after printing the result. The root cause is we are dumping packets into a specific file and trying to post process continuously since packets are being cut into half error is coming after printing the result since its live post processing. Help me in ignoring the error I am getting. I tried using exception handling still error is being printed.

def Validate_IP_Assignment(Capture):
    try:
        capture_file = pyshark.FileCapture(Capture)
        host = None
        assigned_ip = None
        DHCP_Assigned = False
        vehicle_found = 0

        for packet in capture_file:
            
            current_packet_number = int(packet.number)
            
            if (packet.highest_layer.upper() == 'DOIP' or packet.highest_layer.upper() == 'STCSIG'):
                try:
                    if 'vin' in packet.doip.field_names:
                        vehicle_found+=1
                        host = packet.ip.src
                        #if host.startswith(('192.168.88')):                                           
                        #print('DHCP Assigned IP: ',host)
                            

                except Exception as e:
                    print(e)
                    print("Exception 2",packet.highest_layer.upper())
                    pass

        canoe = CANoe()        
        if(vehicle_found >= 3):   
            print("printing the IP address")
            canoe.set_SysVar('wireshark', 'DHCP_server_state_start', 1)
            canoe.set_SysVar('wireshark', 'DHCP_Assigned_IP', host)
            if host.startswith('192.168.88'):
                canoe.set_SysVar('wireshark', 'IP_Type', 'DHCP')
            elif host.startswith('169.254'):   #169.254.213.31
                canoe.set_SysVar('wireshark', 'IP_Type', 'AutoIP')            
        else:
            print("IP address is not assigned")
            canoe.set_SysVar('wireshark', 'DHCP_server_state_start', 0)       
        capture_file.close()
    except pyshark.PySharkException as shark_exception:
        pass
    except pyshark.TSharkCrashException as tshark_exception:
    pass
    except Exception as e:
        pass   

Error after printing the result properly:

    An error occurred: TShark (pid 14148) seems to have crashed (retcode: 2).
    Last error line: tshark: The file "C:/Common_Configuration/wireshark106.pcap" appears to have been cut short in the middle of a packet.
    Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.
    Exception ignored in: <function Capture.__del__ at 0x04202730>
    Traceback (most recent call last):
      File "C:\Users\BCML2RIG\AppData\Roaming\Python\Python39\site-packages\pyshark\capture\capture.py", line 405, in __del__
        self.close()
      File "C:\Users\BCML2RIG\AppData\Roaming\Python\Python39\site-packages\pyshark\capture\capture.py", line 393, in close
        self.eventloop.run_until_complete(self.close_async())
      File "C:\Program Files (x86)\Python39-32\lib\asyncio\base_events.py", line 647, in run_until_complete
        return future.result()
      File "C:\Users\BCML2RIG\AppData\Roaming\Python\Python39\site-packages\pyshark\capture\capture.py", line 397, in close_async
        await self._cleanup_subprocess(process)
    Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.

I am controlling start and stop logging by adding logging block in .pcap format in canoe and using python to post process the logs which is being logged. According to me error is being triggered by pyshark module which is installed in the PC, not sure how to find a fix for it.

6
  • You cannot have an except without a try Commented Mar 4, 2024 at 17:18
  • Please consider the code from def Validate_IP_Assignment(Capture): format is being taken differently on the site Commented Mar 4, 2024 at 19:20
  • Can you then edit the question and correct the formatting? Commented Mar 4, 2024 at 20:17
  • I have corrected it now Commented Mar 4, 2024 at 20:36
  • How are you dumping packets into the file? Commented Jun 18, 2024 at 11:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.