千家信息网

WIN7通过BAT脚本设置IP、DNS、WINS

发表于:2024-10-27 作者:千家信息网编辑
千家信息网最后更新 2024年10月27日,本文通过BAT脚本,实现在WIN7上设置IP等网络信息,以下是示例: 以下是脚本:@ echo off%1 %2ver|find "5.">nul&&goto :stmshta _vbscrip
千家信息网最后更新 2024年10月27日WIN7通过BAT脚本设置IP、DNS、WINS
    本文通过BAT脚本,实现在WIN7上设置IP等网络信息,以下是示例:

    以下是脚本:
@ echo off%1 %2ver|find "5.">nul&&goto :stmshta _vbscript:createobject("shell.application").shellexecute("%~s0","goto :st","","runas",1)(window.close)&goto :eof:stecho/title 修改本机IP地址color 1fecho *****************************************************************echo *                                                               *echo *                    修改本机网卡IP地址                         *echo *                        1.静态地址                             *echo *                        2.自动获取                             *echo *****************************************************************:beginset /p n=请输入要设置的网卡类型(1或2):if "%n%" lss "1" echo 您输入的网卡不存在!请重新输入!!!if "%n%" gtr "2" echo 您输入的网卡不存在!请重新输入!!!echo/if "%n%" lss "1" goto beginif "%n%" gtr "2" goto begin if "%n%" equ "1" goto x1if "%n%" equ "2" goto x2:x1echo 您选择的是:%n%.以太网:begin1set /p a=  请输入静态IP地址(如 192.168.1.2):if "%a%" equ "" goto begin1:begin2set /p b=  请输入子网掩码(如 255.255.255.0):if "%b%" equ "" goto begin2:begin3set /p c=  请输入网关地址(如 192.168.1.1):if "%c%" equ "" goto begin3:begin4set /p d=  请输入DNS地址1(如 114.114.114.114):if "%d%" equ "" goto begin4:begin5set /p e=  请输入DNS地址2(如 211.138.156.66):if "%e%" equ "" goto begin5:begin6set /p f=  请输入WINS地址(如 8.8.8.8):if "%f%" equ "" goto begin6netsh interface ip set address "本地连接" static %a% %b% %c%netsh interface ip set dns "本地连接" static %d% primary>nulnetsh interface ip add dns "本地连接" %e%>nulnetsh interface ip set wins "本地连接" static %f%>nulecho  静态地址设置成功!!!ping -n 5 127.0.0.1>nulgoto:eof:x2echo 选择的是:%n%.自动获取echo *******************************************************echo *        IP即将初始化为自动获取状态……                 *netsh interface ip set address "本地连接" dhcp>nulnetsh interface ip set dns "本地连接" dhcp>nulecho *******************************************************echo DHCP设置成功!!!ping -n 5 127.0.0.1>nulgoto:eofpause
0