@echo off setlocal enabledelayedexpansion ::判断是否为管理员打开 net.exe session 1>NUL 2>NUL && ( goto start ) || ( goto UACPrompt ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :start choice /C 1234 /T 15 /D 3 /M "1.查看所有转发列表,2.映射端口,3.删除映射,4.退出" if errorlevel 4 goto ext if errorlevel 3 goto del if errorlevel 2 goto add if errorlevel 1 goto list :list echo ===============================list=============================== netsh interface portproxy show all echo ================================================================== pause goto start :add set /p listenaddress=请输入监听的ip地址: set /p listenport=请输入监听的端口: set /p connectaddress=请输入转发目标的ip地址: set /p connectport=请输入转发目标的端口: echo use "netsh interface portproxy add v4tov4 listenaddress=!listenaddress! listenport=!listenport! connectaddress=!connectaddress! connectport=!connectport!" netsh interface portproxy add v4tov4 listenaddress=!listenaddress! listenport=!listenport! connectaddress=!connectaddress! connectport=!connectport! goto list :del set /p listenaddress=请输入监听的ip地址: set /p listenport=请输入监听的端口: echo use "netsh interface portproxy del v4tov4 listenport=!listenport! listenaddress=!listenaddress!" netsh interface portproxy del v4tov4 listenport=!listenport! listenaddress=!listenaddress! goto list :ext exit
使用方法:
1.新建空文本文件,将文件名改为:transmit.bat
2.打开文件,将上述代码 复制如文件即可。 注意需要修改一下文本的编码格式为:gb2312