先占个沙发
这是楼主自己写的不?
我想请教个问题,不知道楼主是否熟悉netsh命令
在win7下以管理员身份运行下面的代码- echo interface ipv4 set address "本地连接" dhcp| netsh
- echo dns set dns "本地连接" dhcp |netsh
复制代码 提示命令成功,但是ip设置并不会变成自动获取
使用netsh命令备份下自动获取ip时的设置- netsh -c interface ipv4 dump > e:\ip备份.txt
复制代码 之后该ip为固定ip,再用以下命令恢复备份,失败复制代码 这个是怎么回事,问了好多地方,都没人解答,望楼主能帮忙
我是菜鸟,希望楼主说的简单些
下面是我写的批处理程序- @echo off
- echo.
- echo -------------------------------------------------------------------------------
- echo xp以上系统,请以管理员身份运行,未以管理员身份运行请退出重新以管理员身份运行
- echo -------------------------------------------------------------------------------
- echo 请选择 A,B,C,D,E:
- choice /n /c abcde /m "A为固定ip(学校设置),B为自动ip(一般设置),C 手动设置,D 备份当前地址ip,E 恢复备份的ip:"
- if errorlevel 5 goto bakup
- if errorlevel 4 goto bak
- if errorlevel 3 goto myset
- if errorlevel 2 goto dhcp
- if errorlevel 1 goto static
- :static
- pause
- echo interface ipv4 set address "本地连接" static 192.168.131.21 255.255.255.0 192.168.1.1| netsh
- echo dns set dns "本地连接" static 218.85.157.99 |netsh
- goto over
- :dhcp
- echo interface ipv4 set address "本地连接" dhcp| netsh
- echo dns set dns "本地连接" dhcp |netsh
- goto over
- :myset
- echo ------------------------
- set /p ip=请输入ip,按回车结束:
- echo %ip% >ip.txt
- for /f "delims=. tokens=1-4" %%a in (ip.txt) do set ip1=%%a& set ip2=%%b& set ip3=%%c
- del ip.txt
- if %ip1% lss 127 goto first & pause
- if %ip2% lss 192 ( goto second ) else ( goto third )
- :first
- echo interface ipv4 set address "本地连接" static %ip% 255.0.0.0 %ip1%.%ip2%.%ip3%.1 |netsh
- goto dns
- :second
- echo interface ipv4 set address "本地连接" static %ip% 255.255.0.0 %ip1%.%ip2%.%ip3%.1 |netsh
- goto dns
- :third
- echo interface ipv4 set address "本地连接" static %ip% 255.255.255.0 %ip1%.%ip2%.%ip3%.1 |netsh
- goto dns
- :dns
- echo dns set dns "本地连接" static 218.85.157.99 |netsh
- goto over
- :over
- cls
- echo.
- echo --------------------------------------------------
- echo.
- echo ip设置完成
- echo.
- echo --------------------------------------------------
- pause
- exit
- :bak
- echo -----------------------------------------------------------------------
- echo 备份当前的ip设置,将在e盘根目录下生成:ip备份.txt
- echo 请保存好,勿随意移动备份文件
- echo -----------------------------------------------------------------------
- pause
- netsh -c interface ipv4 dump > e:\ip备份.txt
- echo.
- echo -----------------------------------------------------------------------
- echo 备份完成,请保管好备份文件
- echo -----------------------------------------------------------------------
- start e:\
- pause
- exit
- :bakup
- echo -----------------------------------------------------------------------
- echo 请确认备份文件:ip备份.txt 和本程序放在同一目录下
- echo ************************************
- echo -----------------------------------------------------------------------
- pause
- echo.
- if not exist e:\ip备份.txt echo ip备份.txt 不存在!请将备份文件移至E盘根目录下 & start e:\ & pause
- netsh -f e:\ip备份.txt
- echo -----------------------------------------------------------------------
- echo ip已还原
- echo -----------------------------------------------------------------------
- pause
复制代码
|