fetch-h2 绑定网卡中指定ip发送请求

fetch-h2
创建时间:2025-04-15 00:40:33

ipv6

import {context} from 'fetch-h2'
const ctx = context({HttpProtocols: 'http2',session:{
        localAddress: 'your ipv6'
    }});

 

setTimeout(async ()=>{
    let ret = await (
        await ctx.fetch('https://api.ip.sb/ip')
    ).text();
    console.log(ret)
},0)

ipv4

import {context} from 'fetch-h2'
const ctx = context({HttpProtocols: 'http2',session:{
        localAddress: 'your ipv4',
	family: 4,//!!!!
    }});

 

setTimeout(async ()=>{
    let ret = await (
        await ctx.fetch('https://api.ip.sb/ip')
    ).text();
    console.log(ret)
},0)