npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xiaobaidadada/node-tuntap2-wintun

v1.0.5

Published

create tun in linux or windows

Downloads

120

Readme

node-tuntap2

a opensource, asynchronized, napi-based, business friendly tuntap device driver addon for nodejs.

Node.js CI Node.js Package

Package quality

install

npm install @xiaobaidadada/node-tuntap2-wintun

TL; DR

const {Tun, Tap} = require('@xiaobaidadada/node-tuntap2-wintun');

try {
    const tun = new Tun();
    tun.mtu = 1400;
    tun.ipv4 = '10.0.0.100/24';
    tun.ipv6 = 'abcd:1:2:3::/64';
    tun.on('data', (buf) => {
        console.log('received:', buf);
    })
    tun.isUp = true;
    console.log(`created tun: ${tun.name}, ip: ${tun.ipv4}, ${tun.ipv6}, mtu: ${tun.mtu}`);
    tun.release();

}
catch(e) {
	console.log('error: ', e);
	process.exit(0);
}
// widnwos 
const {Wintun} = require("@xiaobaidadada/node-tuntap2-wintun")

const p2 = Wintun.get_wintun_dll_path();
Wintun.wintunSetPath(p2);
Wintun.wintunInit();
Wintun.wintunSetIpv4("tuntap2","10.6.7.7",24);
Wintun.wintunUpOn((buf)=>{
    // 解析 IP 头部
    const version = buf[0] >> 4;
    const headerLength = (buf[0] & 0x0f) * 4;
    const protocol = buf[9];
    if (version !== 4) {
        console.log('不是 IPv4');
        return;
    }
    const sourceIP = buf.slice(12, 16).join('.');
    const destIP = buf.slice(16, 20).join('.');
    console.log(`Source IP: ${sourceIP}`);
    console.log(`Destination IP: ${destIP}`);

    // console.log("数据:"+buf);
});
// Wintun.wintunSend(sessionHandle,buffer);

Note: 目前仅支持linux和windows ;本项目使用了预构建,建议使用Node18,不需要编译而是从github下载编译好的文件,如果你电脑上的网络安装的时候无法访问github则会退化成编译。在windows上编译可能遇到的问题可以参考这个链接https://blog.csdn.net/jjocwc/article/details/134152602

Note: Reading properties requires your interface in up status.

Note: For a Tun device, mac property is readonly.

Node: Please make sure the first 8bits is 00 for setting the mac address of a Tap device.

Streams API

The tuntap object supports Node.js Duplex interface. However, almost all streams api methods is a wrapper of fs.ReadStream or fs.WriteStream. The writing and events are based on them.

Performance

The writing and reading of tuntap is based on nodejs fs and readingStream. This means these methods is running on libuv threads pool. Please set the threads pool size properly for your application.