1 Star 0 Fork 1

小呆11222/docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wsl子系统端口转发 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
小呆11222 提交于 2023-10-27 02:32 . 1
/usr/bin/getip
```
ip addr | awk '/^[0-9]+: / {}; /inet.*global.*eth/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}'
```
d:\ip.vbs
d:\Temp
```
wslname = "Ubuntu" 'the name of your wls system, could be checked by command wsl -l
Dim ports
'the ports which need to process ip forward
ports = Array(80,443)
'the file to store wls ip
ipTemp = "D:\Temp\wslip.txt"
If WScript.Arguments.Length = 0 Then
'to get the admin right to run the ip forward commands
CreateObject("Shell.Application").ShellExecute "wscript.exe" _
, """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1
WScript.Quit
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
'to get the eth0 ip address of the sub linux system, the script getip is in /usr/bin, and save the ipadress to C:\Temp\wslip.txt
writeip = objShell.Run("cmd /c ""wsl -d " + wslname + " -u root getip"">" + ipTemp,0,True)
'wscript.sleep(1000)'just incase some network problem
'get the ip from ip file
Set f = fso.OpenTextFile(ipTemp, 1)
wslip = f.ReadAll()
f.Close()
'execute the ip forward command for each port number from the list
For i = 0 To UBound(ports)
port = ports(i)
command = "cmd /c ""netsh interface portproxy add v4tov4 listenport=" & port & " listenaddress=0.0.0.0 connectport=" & port & " connectaddress=" + wslip
forwarding = objShell.Run(command,0,True)
Next
```
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/xiaodaidi1/docs.git
git@gitee.com:xiaodaidi1/docs.git
xiaodaidi1
docs
docs
main

搜索帮助

D67c1975 1850385 1daf7b77 1850385