Created
August 19, 2021 00:58
-
-
Save agusibrahim/629c1abfe2e37e983f6fd7285c953932 to your computer and use it in GitHub Desktop.
Expose your WSL port to other device (same network)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const execSync = require('child_process').execSync; | |
async function main (){ | |
var wslip=(await execSync("bash -c \"hostname --all-ip-addresses\"")+"").replace(" ","").replace("\n","") | |
try{ | |
await execSync("NET SESSION >nul 2>&1") | |
}catch{ | |
console.log("Please run as Administrator") | |
return | |
} | |
if(process.argv.length<2 || isNaN(process.argv[2])){ | |
console.log("port invalid") | |
return | |
} | |
if(parseInt(process.argv[2])<1){ | |
var rst=await execSync("netsh.exe interface portproxy reset") | |
var lst=execSync("netsh.exe interface portproxy show all") | |
console.log(rst+" RESET OK: "+lst) | |
return | |
} | |
port=process.argv[2] | |
cmd="netsh.exe interface portproxy add v4tov4 listenport="+port+" listenaddress=0.0.0.0 connectport="+port+" connectaddress="+wslip | |
var res=execSync(cmd) | |
var lst=execSync("netsh.exe interface portproxy show all") | |
console.log(res+" OK: "+lst) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exec
node expose_wsl_port.js 6677
as Administratorwhich
6677
is your portto reset, pass
0
as port