title: How To Capture network packets to MySQL
body: <p>I'm going to design a network Analyzer for WiFi (802.11)
  Currently I use tshark to capture and parse the WiFi frames and then pipe the output to a perl script to store the parsed information to Mysql database.</p>
  
  <p>I just find out that I miss alot of frames in this process. I checked and the frames seem to be lost during the Pipe (when the output is delivered to perl to get srored in Mysql)
  Here is how it goes </p>
  
  <p>(Tshark) -------frames are lost----> (Perl) --------> (MySQL)
  this is the how I pipe the output of tshark to script:</p>
  
  <pre><code>sudo tshark -i mon0 -t ad -T fields -e frame.time -e frame.len -e frame.cap_len -e radiotap.length | perl tshark-sql-capture.pl 
  </code></pre>
  
  <p>this is  simple template of the perl script I use (tshark-sql-capture.pl)</p>
  
  <pre><code># preparing the MySQL
  my $dns = "DBI:mysql:capture;localhost";
  my $dbh = DBI-&gt;connect($dns,user,pass);
  my $db = "captured";
  
  while (&lt;STDIN&gt;) {
      chomp($data = &lt;STDIN&gt;);
      ($time, $frame_len, $cap_len, $radiotap_len) = split "  ", $data;
      my $sth = $dbh-&gt; prepare("INSERT INTO $db VALUES (str_to_date('$time','%M %d, %Y %H:%i:%s.%f'), '$frame_len', '$cap_len', '$radiotap_len'\n)" );
      $sth-&gt;execute;
  }
  
  #Terminate MySQL
  $dbh-&gt;disconnect;
  </code></pre>
  
  <p>Any Idea which can help to make the performance better is appreciated.Or may be there is an Alternative mechanism which can do better.
  Right now my performance is 50% means I can store in mysql around half of the packets I'v captured.</p>