添加新地址后立即发出 EADDRNOTAVAIL 中的 nodejs http 请求
nodejs http request immediately after adding a new address result in EADDRNOTAVAIL
//nodejs code
var ip=<some_ip_address>;
//for me it is 2001:250:401:3611:50c6:6b18:e8f7:f882
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
然后输出
{[Error: bind EADDRNOTAVAIL 2001:250:401:3611:50c6:6b18:e8f7:f882]
code: 'EADDRNOTAVAIL',
errno: 'EADDRNOTAVAIL',
syscall: 'bind',
address: '2001:250:401:3611:50c6:6b18:e8f7:f882' }
第二次
(实际上我正在测试 address ,因为我们的 DHCP-stateless 坏了)
{ [Error: connect ETIMEDOUT 2404:6800:4005:805::200e:80]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '2404:6800:4005:805::200e',
port: 80 }
我可以从第二次输出中提取,
new-netipaddress 确实添加了正确的地址,所以回调 运行 很好(虽然超时,这是我们设计的)
但第一次回调失败,显示 EADDRNOTAVAIL
那么为什么第一个 运行 失败了?以及如何避免?
感谢@SanderSteffann 对暂定地址的了解,我想到了一个解决方案,但可能不是很好
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
execSync('powershell get-netipaddress '+ip)
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
line 2:++++execSync('powershell get-netipaddress '+ip)
//nodejs code
var ip=<some_ip_address>;
//for me it is 2001:250:401:3611:50c6:6b18:e8f7:f882
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
然后输出
{[Error: bind EADDRNOTAVAIL 2001:250:401:3611:50c6:6b18:e8f7:f882]
code: 'EADDRNOTAVAIL',
errno: 'EADDRNOTAVAIL',
syscall: 'bind',
address: '2001:250:401:3611:50c6:6b18:e8f7:f882' }
第二次 (实际上我正在测试 address ,因为我们的 DHCP-stateless 坏了)
{ [Error: connect ETIMEDOUT 2404:6800:4005:805::200e:80]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '2404:6800:4005:805::200e',
port: 80 }
我可以从第二次输出中提取,
new-netipaddress 确实添加了正确的地址,所以回调 运行 很好(虽然超时,这是我们设计的)
但第一次回调失败,显示 EADDRNOTAVAIL
那么为什么第一个 运行 失败了?以及如何避免?
感谢@SanderSteffann 对暂定地址的了解,我想到了一个解决方案,但可能不是很好
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
execSync('powershell get-netipaddress '+ip)
http.request({
host:'2404:6800:4005:805::200e',//just use google as an example
family:6,
localAddress:ip
},(res)=>{
console.log('reachable');
}).on('error',(e)=>{
console.log(e);
})
}).stdin.end();
line 2:++++execSync('powershell get-netipaddress '+ip)