@@ -0,0 +1,2299 @@
+#!/usr/bin/python%0A# Copyright (C) 2014 Amri Abdesslem%0A#%0A# This program is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# This program is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A#%0A#--------------------------------------------------------------------%0A%0A__author__ = 'ask3m'%0A%0A#--------------------------------------------------------------------%0A%0Aimport os.path%0Aimport os%0Aimport gzip%0Aimport string%0A%0Aclass pcapGzip:%0A    def __init__(self, pcapfile, reportpath=%22./report%22):%0A        assert pcapfile%0A        if not os.path.exists(pcapfile):%0A            raise TypeError(%22Pcap file not found. Please check location.%22)%0A        self.reportpath = reportpath%0A        if not os.path.exists(self.reportpath):%0A            os.makedirs(self.reportpath)%0A        self.pcapfile = pcapfile%0A%0A    def uncompressGzip(self, file):%0A        %22%22%22Gunzip a gz file%0A        %22%22%22%0A        try:%0A            r_file = gzip.GzipFile(file, 'r')%0A            write_file = string.rstrip(file, '.gz')%0A            w_file = open(write_file, 'w')%0A            w_file.write(r_file.read())%0A            w_file.close()%0A            r_file.close()%0A            os.unlink(file)%0A            print %22Successfully uncompressed %25s%22 %25 (file)%0A        except:%0A            print %22***Error: Failed to uncompress %25s%22 %25 (file)%0A%0A    def tagFiles(self):%0A        %22%22%22 Browses a given dir and tries to uncompress gz files%0A        %22%22%22%0A        listDir = os.listdir(%22report%22)%0A        for f in listDir:%0A            fullpath = os.path.join(self.reportpath, f) # full path without gz extension%0A            if open(fullpath, 'r').read(2)=='%5C037%5C213': # magic number for application/x-gzip%0A                os.rename(fullpath, fullpath+%22.gz%22)     # first give gz extension to gz files%0A                self.uncompressGzip(fullpath+%22.gz%22)     # then uncompress gz files%0A%0A%0A

decompress gzip file