|
| 1 | +# nodeshark |
| 2 | + |
| 3 | +Wrapper around libwireshark providing network packet dissection for [node.js](http://nodejs.org/). |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | + $ npm install nodeshark |
| 8 | + |
| 9 | +### Build |
| 10 | + |
| 11 | +```bash |
| 12 | +$ svn co http://anonsvn.wireshark.org/wireshark/trunk/ wireshark |
| 13 | +$ cd wireshark |
| 14 | +$ ./autogen.sh |
| 15 | +$ ./configure |
| 16 | +$ make |
| 17 | +$ sudo make install |
| 18 | +$ export WIRESHARK_INCLUDE_DIR=[wireshark source directory] |
| 19 | +$ node-waf configure build |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +```javascript |
| 25 | +var nodeshark = require("nodeshark"); |
| 26 | + |
| 27 | +var dissector = new nodeshark.Dissector(nodeshark.LINK_LAYER_TYPE_ETHERNET); |
| 28 | + |
| 29 | +var rawPacket = { |
| 30 | + header: { |
| 31 | + timestampSeconds: 10, |
| 32 | + timestampMicroseconds: 20, |
| 33 | + capturedLength: buffer.length, |
| 34 | + originalLength: buffer.length |
| 35 | + }, |
| 36 | + data: new Buffer([ |
| 37 | + 0x58, 0x6d, 0x8f, 0x67, 0x8a, 0x4d, 0x00, 0x1b, 0x21, 0xcf, 0xa1, 0x00, 0x08, 0x00, 0x45, 0x00, |
| 38 | + 0x00, 0x3b, 0xd1, 0xb0, 0x40, 0x00, 0x40, 0x11, 0xc5, 0xde, 0x0a, 0x14, 0x08, 0x65, 0xc0, 0xa8, |
| 39 | + 0xd0, 0x01, 0xc5, 0x32, 0x00, 0x35, 0x00, 0x27, 0xa3, 0x5b, 0x65, 0x89, 0x01, 0x00, 0x00, 0x01, |
| 40 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6d, 0x61, 0x69, 0x6c, 0x04, 0x6c, 0x69, 0x76, 0x65, |
| 41 | + 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 |
| 42 | + ]); |
| 43 | +}; |
| 44 | +var packet = dissector.dissect(rawPacket); |
| 45 | + |
| 46 | +// OR |
| 47 | + |
| 48 | +var buffer = new Buffer([ |
| 49 | + 0x58, 0x6d, 0x8f, 0x67, 0x8a, 0x4d, 0x00, 0x1b, 0x21, 0xcf, 0xa1, 0x00, 0x08, 0x00, 0x45, 0x00, |
| 50 | + 0x00, 0x3b, 0xd1, 0xb0, 0x40, 0x00, 0x40, 0x11, 0xc5, 0xde, 0x0a, 0x14, 0x08, 0x65, 0xc0, 0xa8, |
| 51 | + 0xd0, 0x01, 0xc5, 0x32, 0x00, 0x35, 0x00, 0x27, 0xa3, 0x5b, 0x65, 0x89, 0x01, 0x00, 0x00, 0x01, |
| 52 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6d, 0x61, 0x69, 0x6c, 0x04, 0x6c, 0x69, 0x76, 0x65, |
| 53 | + 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 |
| 54 | +]); |
| 55 | +var packet = dissector.dissect(buffer); |
| 56 | +``` |
| 57 | + |
| 58 | +You can also use it it conjunction with [pcap-parser](https://github.com/nearinfinity/node-pcap-parser). |
| 59 | + |
| 60 | +```javascript |
| 61 | +var pcapp = require('pcap-parser'); |
| 62 | + |
| 63 | +var parser = new pcapp.Parser('/path/to/file.pcap'); |
| 64 | +var dissector; |
| 65 | +parser.on('globalHeader', function(globalHeader) { |
| 66 | + dissector = new nodeshark.Dissector(globalHeader.linkLayerType); |
| 67 | +}); |
| 68 | +parser.on('packet', function(rawPacket) { |
| 69 | + var packet = dissector.dissect(rawPacket); |
| 70 | +}); |
| 71 | +parser.parse(); |
| 72 | +``` |
| 73 | + |
| 74 | +## License |
| 75 | + |
| 76 | +(The MIT License) |
| 77 | + |
| 78 | +Copyright (c) 2012 Near Infinity Corporation |
| 79 | + |
| 80 | +Permission is hereby granted, free of charge, to any person obtaining |
| 81 | +a copy of this software and associated documentation files (the |
| 82 | +"Software"), to deal in the Software without restriction, including |
| 83 | +without limitation the rights to use, copy, modify, merge, publish, |
| 84 | +distribute, sublicense, and/or sell copies of the Software, and to |
| 85 | +permit persons to whom the Software is furnished to do so, subject to |
| 86 | +the following conditions: |
| 87 | + |
| 88 | +The above copyright notice and this permission notice shall be |
| 89 | +included in all copies or substantial portions of the Software. |
| 90 | + |
| 91 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 92 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 93 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 94 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 95 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 96 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 97 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 commit comments