- 
                Notifications
    You must be signed in to change notification settings 
- Fork 444
Feature pipe captures #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            CarlyAmar
  wants to merge
  9
  commits into
  KimiNewt:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
CarlyAmar:feature-pipe-captures
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f77aedd
              
                Add use_json to LiveRingCapture
              
              
                CarlyAmar 2e84769
              
                Updated PipeCapture to work correctly
              
              
                CarlyAmar 7461375
              
                Added Pipe Ring Capture
              
              
                CarlyAmar 2549372
              
                Added exception to disallow display filters
              
              
                CarlyAmar 8c11c84
              
                Inherit from capture
              
              
                CarlyAmar 101afc9
              
                remove unnecessary override
              
              
                CarlyAmar dcb060a
              
                Added documentation and argument handling
              
              
                CarlyAmar 53614a7
              
                Merge branch 'master' of https://github.com/KimiNewt/pyshark into fea…
              
              
                CarlyAmar a72b47e
              
                Went back to old version of accepting arguments
              
              
                CarlyAmar File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from pyshark.capture.pipe_capture import PipeCapture | ||
| from pyshark.capture.capture import TSharkCrashException, TSharkVersionException | ||
| from pyshark.tshark.tshark import tshark_supports_json | ||
| import asyncio | ||
| import subprocess | ||
| import tempfile | ||
|  | ||
|  | ||
| class DisplayFilterNotAllowedException(Exception): | ||
| """Display Filters are not allowed in PipeRingCapture.""" | ||
|  | ||
|  | ||
| class PipeRingCapture(PipeCapture): | ||
| """ | ||
| Represents a live ringbuffer capture on a network interface. | ||
| """ | ||
|  | ||
| def __init__(self, pipe, ring_file_size=1024, num_ring_files=2, ring_file_name=None, | ||
| only_summaries=False, decryption_key=None, | ||
| encryption_type='wpa-pwk', decode_as=None, disable_protocol=None, display_filter=None, | ||
| tshark_path=None, override_prefs=None, include_raw=False, use_json=False, eventloop=None): | ||
| """ | ||
| Creates a new live capturer on a given interface. Does not start the actual capture itself. | ||
| :param ring_file_size: Size of the ring file in kB, default is 1024 | ||
| :param num_ring_files: Number of ring files to keep, default is 1 | ||
| :param ring_file_name: Name of the ring file, default is /tmp/pyshark.pcap | ||
| :param interface: Name of the interface to sniff on or a list of names (str). If not given, runs on all interfaces. | ||
| :param bpf_filter: BPF filter to use on packets. | ||
| :param display_filter: Display (wireshark) filter to use. | ||
| :param only_summaries: Only produce packet summaries, much faster but includes very little information | ||
| :param decryption_key: Optional key used to encrypt and decrypt captured traffic. | ||
| :param encryption_type: Standard of encryption used in captured traffic (must be either 'WEP', 'WPA-PWD', or | ||
| 'WPA-PWK'. Defaults to WPA-PWK). | ||
| :param decode_as: A dictionary of {decode_criterion_string: decode_as_protocol} that are used to tell tshark | ||
| to decode protocols in situations it wouldn't usually, for instance {'tcp.port==8888': 'http'} would make | ||
| it attempt to decode any port 8888 traffic as HTTP. See tshark documentation for details. | ||
| :param tshark_path: Path of the tshark binary | ||
| :param override_prefs: A dictionary of tshark preferences to override, {PREFERENCE_NAME: PREFERENCE_VALUE, ...}. | ||
| :param disable_protocol: Tells tshark to remove a dissector for a specifc protocol. | ||
| """ | ||
| if display_filter is not None: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible simply not to have it as a parameter in the init and just to write it in the doc. This is a bit more explicit so I'm not 100% about it. | ||
| raise DisplayFilterNotAllowedException("Display Filters are not allowed in PipeRingCapture.") | ||
|  | ||
| super(PipeRingCapture, self).__init__(pipe, display_filter=None, only_summaries=only_summaries, | ||
| decryption_key=decryption_key, encryption_type=encryption_type, | ||
| tshark_path=tshark_path, decode_as=decode_as, disable_protocol=disable_protocol, | ||
| override_prefs=override_prefs, include_raw=include_raw, use_json=use_json, eventloop=eventloop) | ||
|  | ||
| self.ring_file_size = ring_file_size | ||
| self.num_ring_files = num_ring_files | ||
| if ring_file_name is None: | ||
| self.ring_file_name = tempfile.mktemp(suffix=".pcap", prefix="pyshark_") | ||
| else: | ||
| self.ring_file_name = ring_file_name | ||
|  | ||
| def get_parameters(self, packet_count=None): | ||
| """ | ||
| Returns the special tshark parameters to be used according to the configuration of this class. | ||
| """ | ||
| params = super(PipeRingCapture, self).get_parameters()[:-2] | ||
| params.extend(['-i', self._pipe]) | ||
| params += ['-b', 'filesize:' + str(self.ring_file_size), '-b', 'files:' + str(self.num_ring_files), '-w', | ||
| self.ring_file_name, '-P'] | ||
| return params | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to how RingCaptures work, Tshark will not allow a display filter in this class.