https://github.com/yiweisong/node-ace-pcap
Capture packet in a specified network
https://github.com/yiweisong/node-ace-pcap
capture node-addon-api pcap
Last synced: 10 months ago
JSON representation
Capture packet in a specified network
- Host: GitHub
- URL: https://github.com/yiweisong/node-ace-pcap
- Owner: yiweisong
- Created: 2022-11-17T07:08:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-08T07:46:37.000Z (over 2 years ago)
- Last Synced: 2025-01-17T04:33:46.232Z (11 months ago)
- Topics: capture, node-addon-api, pcap
- Language: C++
- Homepage:
- Size: 146 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Aceinna PCap
This is a node-addon-api native addon to capture packet from a specifed network. Some code is referenced from https://github.com/mscdex/cap.git
> You need to have Node 10.5.0 or later installed.
## How to use
### Install
```
npm install ace-pcap
```
### Sample Code
> Basic
```Javascript
import { EthernetPacketCapture, GetNetworkInterface } from 'ace-pcap'
const ip = '192.168.22.140'; // IP Address of network for capture packet
const iface = GetNetworkInterface(ip);
const instance = new EthernetPacketCapture({ iface });
instance.on('data', (data) => {
console.log(data);
})
instance.start();
```
> Filter
```Javascript
import { EthernetPacketCapture, GetNetworkInterface } from 'ace-pcap'
const ip = '192.168.22.140'; // IP Address of network for capture packet
const filter = `ether src 88:e9:fe:52:68:56`;
const iface = GetNetworkInterface(ip);
const instance = new EthernetPacketCapture({ iface, filter });
instance.on('data', (data) => {
console.log(data);
})
instance.start();
// update filter while capturing
setTimeout(()=>{
instance.setFilter('ether src 98:5f:d3:3c:ab:fd');
},5000)
```
> Send packet to network
```Javascript
import { EthernetPacketCapture, GetNetworkInterface } from 'ace-pcap'
const ip = '192.168.22.140'; // IP Address of network for capture packet
const iface = GetNetworkInterface(ip);
const instance = new EthernetPacketCapture({ iface });
instance.start();
// update filter while capturing
setTimeout(()=>{
instance.send(Buffer.from('data to send'))
},5000)
```