我试图制作批处理文件,使用时会设置ip。我认为我实现了这一点。垮台是我希望它能够在我使用它时传递一个变量。例如,SETIP 37.将变量37插入ip。
以下是我的代码
rem Network Settings for IP
netsh interface ip set address name = "Local Area Connection" source = static addr = 192.168.10.(target for variable) mask = 255.255.255.0
netsh interface ip set address name = "Local Area Connection" gateway = 192.168.10.1 gwmetric = 1
netsh interface ip set dns name = "Local Area Connection" source = static addr = 192.168.10.1
netsh interface ip show config
pause
答案 0 :(得分:0)
您可以轻松地创建命令行工具。将下面的脚本保存为SetupIP.bat
,然后调用它(从提升的提示符),如下所示:
SetupIP 132
以上将设置IP地址为192.168.10.132的网络。
脚本源,它是您上面的命令,接受IP地址最后部分的命令行参数:
@ECHO OFF
REM Usage:
REM SetupIP {'D' IP address component}
REM Note that this command requires elevated rights, so it must be run as an administrator.
REM Validate a value was entered.
IF "%~1"=="" (
ECHO No IP value was provided.
ECHO Enter only the last component of the IP address to configure.
GOTO :EOF
)
rem Network Settings for IP
netsh interface ip set address name = "Local Area Connection" source = static addr = 192.168.10.%~1 mask = 255.255.255.0
netsh interface ip set address name = "Local Area Connection" gateway = 192.168.10.1 gwmetric = 1
netsh interface ip set dns name = "Local Area Connection" source = static addr = 192.168.10.1
netsh interface ip show config