libpcap-ffi
- libpcap
FFI wrapper for Node.js
Supports Windows, macOS and Linux.
This project was made possible thanks to koffi
, an awesome and fast C FFI module for Node.js.
Since koffi
is made for Node.js, compatibility with Bun or Deno is not guaranteed but could be possible.
You'll need to install Npcap.
Check that you have the wpcap.dll
file at C:\Windows\System32\Npcap\wpcap.dll
- should be the default location.
Note that libpcap-ffi
may not be compatible with WinPcap
so if you had WinPcap installed before, you'll need to uninstall it or
find a way to use the wpcap.dll
from Npcap instead of the one from WinPcap.
You need to have libpcap.dylib
installed on your system.
It's apparently already installed on macOS, but if it's not, you can install it using Homebrew:
brew install libpcap
You need to have libpcap.so
installed on your system.
Every functions can be directly imported from libpcap-ffi
, so if you want to use findAllDevs
, you can simply do:
// ESM
import { findAllDevs } from "libpcap-ffi";
// CJS
const { findAllDevs } = require("libpcap-ffi");
// Just use it !
const devices = await findAllDevs();
console.log(devices);
/** >>> Returns the following array:
* [
* {
* name: '\\Device\\...',
* description: '...',
* addresses: [ ... ],
* flags: 22
* },
* ...
* ]
*/
Note that we use pnpm
to manage dependencies.
Command | Description |
---|---|
pnpm install |
Install the dependencies |
pnpm build |
Bundle src directory into dist |
You should install globally tsx
.
npm i -g tsx
# Now you can run the examples.
tsx ./examples/devices.ts
A list of things to do to make the library more complete.
-
pcap_open_live
(work in progress) -
pcap_datalink
-
pcap_loop
-
pcap_close