node.js - nodejs http request immediately after adding a new address result in EADDRNOTAVAIL -
//nodejs code var ip=<some_ip_address>; //for me 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 example family:6, localaddress:ip },(res)=>{ console.log('reachable'); }).on('error',(e)=>{ console.log(e); }) }).stdin.end();
then output
{[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' }
the 2nd time (actually testing address , since our dhcp-stateless broken)
{ [error: connect etimedout 2404:6800:4005:805::200e:80] code: 'etimedout', errno: 'etimedout', syscall: 'connect', address: '2404:6800:4005:805::200e', port: 80 }
me can draw 2nd time output,
new-netipaddress did add address properly, callback runs well(although timeout, designed be)
but in 1st time callback failed eaddrnotavail
so why failed first run? , how avoid it?
thanks @sandersteffann 's knowledge on tentative address, think of solution may not good
exec('powershell new-netipaddress '+ip+' -interfacealias wlan',(e,so,se)=>{ http.request({ host:'2404:6800:4005:805::200e',//just use google 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 example family:6, localaddress:ip },(res)=>{ console.log('reachable'); }).on('error',(e)=>{ console.log(e); }) }).stdin.end();
line 2:++++execsync('powershell get-netipaddress '+ip)
Comments
Post a Comment