raw-network-listener
v1.0.1
Published
Wrapper around the "cap" module that listens for packets on network interfaces
Downloads
3
Readme
raw-network-listener
Wrapper around cap that listens for packets on network interfaces.
Uses pcap filters.
$ npm install raw-network-listener
Usage
const rnl = require('raw-network-listener')
const loopback = rnl({
interface: 'lo0',
filter: '(icmp) and (src net 9.8.7.6)' // https://www.tcpdump.org/manpages/pcap-filter.7.html
})
console.log('Link type:', loopback.linkType)
loopback.on('packet', packet => {
console.log('New packet received:', packet.toString('hex'))
})
API
.decoders
From cap.decoders
.findDevice()
From cap.Cap.findDevice
.deviceList()
From cap.Cap.deviceList
({ interface, filter })
Create listener on the interface
(e.g. lo0
or eth0
) with the filter. Filters are based on pcap filters.
.on('packet', packet => ...)
Is emitted when a new packet is registered on the interface. packet
is a buffer.
.linkType
The link type of the interface
.send()
From cap.Cap().send
.close()
From cap.Cap().close