Created
April 30, 2016 01:46
-
-
Save typcn/b6f4391a118bcaa7ee34a40216868422 to your computer and use it in GitHub Desktop.
Extract HTTP body in Wireshark TCP Stream to files
This file contains 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
var fs = require('fs'); | |
var bsplit = require('buffer-split'); | |
var p1 = fs.readFileSync('./part1'); | |
write(p1); | |
function write(px) { | |
var pkts = bsplit(px,new Buffer('GET ')); | |
for (var i = 1; i < pkts.length; i++) { | |
var dta = bsplit(pkts[i], new Buffer('\r\n\r\n')); | |
var url = bsplit(dta[0], new Buffer(' HTTP/1.1'))[0]; | |
var path = url.toString(); | |
ensureDirectoryExistence(path); | |
var data = dta[2]; | |
fs.writeFileSync(path,data); | |
} | |
} | |
function ensureDirectoryExistence(filePath) { | |
var path = require('path'); | |
var dirname = path.dirname(filePath); | |
if (directoryExists(dirname)) { | |
return true; | |
} | |
ensureDirectoryExistence(dirname); | |
fs.mkdirSync(dirname); | |
} | |
function directoryExists(path) { | |
try { | |
return fs.statSync(path).isDirectory(); | |
} | |
catch (err) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment