一键把动态IP自动设置为静态IP

一键把动态IP自动设置为静态IP

问题描述

平时在调试网络模块时,常常需要手动设置IP,然后才可以开始调试网络模块。调试完之后又需要手动设置IP为动态获取。一直就像用批处理来解决,但是一直懒没做,现在来回改IP改烦了就说搞一下。

自动获取

将以下脚本保存为“自动获取IP.bat”, 注意:文本一定要是ANSI编码。

@echo off
netsh interface ip set address name="以太网" source=dhcp
netsh interface ip set dns name="以太网" source=dhcp

echo set complete,  press any key exit.
pause

固定修改

将以下脚本保存为“设置静态ip.bat”, 注意:文本一定要是ANSI编码。

@echo off
netsh interface ip set address name="以太网" source=static addr=192.168.1.2 mask=255.255.252.0 gateway=192.168.1.1
netsh interface ip set dns name="以太网" dhcp

echo set complete,  press any key exit.
echo
pause


注:
需要使用管理员权限才可以运行。
我这里是按照我自己的需要来的,大家使用时需要将Ethernet改为你的网卡名称,然后把我的ip等都换成你们的即可。

猜你喜欢

转载自blog.csdn.net/tang_chuanlin/article/details/80330026