能否有脚本实现一键配置IPv4地址?
办公环境,有两根网线,一个公网一个内网公网从交换机上自动获取IP地址,内网需要手动配置IP、子网掩码和网关
每次插拔网线也就罢了,关键是上内网还得重新配置比较麻烦,有没有脚本程序能一键切换的?或者python也行
如果it没禁止,干脆闲鱼捡个便宜路由器刷系统双拨,网线的麻烦都省了 本帖最后由 braverbt 于 2020-4-28 10:52 编辑
bat来写很简单.
语法:
netsh interface ip set address "网卡名称" static 192.168.0.10 255.255.255.0 192.168.0.1 1
反过来修改为dhcp
netsh interface ip set address "网卡名称" dhcp
自己写一下goto做选择即可~ 修改不到代码块,重新发一下补充修改dns的命令,配合上下文使用
// dns 修改为静态地址
netsh interface ip set dns "网卡名称" static 192.168.0.200
//修改为dhcp分配
netsh interface ip set dns "网卡名称" dhcp 可以的。
我就这样干的。
记得脚本需要在管理员权限下面运行。
—— 来自 HUAWEI EVR-AL00, Android 10上的 S1Next-鹅版 v2.2.2.1 本帖最后由 orecheng 于 2020-4-28 18:08 编辑
有,还包括修改MAC码。仅限WIN10,WIN7改改应该也能用,“以太网”是你的网卡
@echo off
cd /d %~dp0
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
title --IP自动设置 --
MODE con: COLS=80 lines=30
color 0a
:begin
@rem cls
echo 要把IP设置为自动获取 请按 1
echo 要把IP设置为192.168.1.123(内网)请按 2
echo 要把IP设置为10.252.222.222(外网)请按 3
echo 要退出 请按 4
echo.
choice /c 123450 /n /m " 请选择【1-4】:"
echo %errorlevel%
if %errorlevel% == 1 goto set_ip1_ip
if %errorlevel% == 2 goto set_ip2_ip
if %errorlevel% == 3 goto set_ip3_ip
if %errorlevel% == 4 goto end
if %times% == 0 (goto **_connect) else (goto begin)
:set_ip1_ip
echo IP自动设置开始....
echo.
echo 自动获取IP地址....
netsh interface ip set address "以太网" dhcp
echo 自动获取DNS服务器....
netsh interface ip set dns "以太网" dhcp
@rem 设置自动获取IP
@set reg=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001
@set MAC=00E07096537F
@reg add "%reg%" /v NetworkAddress /t reg_SZ /d "%MAC%" /f
echo 设置完成
@set INTERFACE=以太网
echo 重启本机网卡...
netsh interface set interface "%INTERFACE%" disable
netsh interface set interface "%INTERFACE%" enable
pause
goto end
:set_ip2_ip
echo IP自动设置开始....
echo.
echo 正在设置IP、子网掩码、网关
netsh interface ipv4 set address "以太网" "static" "192.168.1.123" "255.255.255.0" "192.168.1.1"
netsh interface ipv4 set dnsservers name="以太网"static114.114.114.114
netsh interface ipv4 add dnsservers name="以太网" 223.5.5.5 index=2
echo 修改网卡Mac...
@set reg=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001
@set MAC=00E07096537F
@reg add "%reg%" /v NetworkAddress /t reg_SZ /d "%MAC%" /f
echo 设置完成
@set INTERFACE=以太网
echo 重启本机网卡...
netsh interface set interface "%INTERFACE%" disable
netsh interface set interface "%INTERFACE%" enable
pause
goto end
:set_ip3_ip
echo IP自动设置开始....
echo.
echo 正在设置IP、子网掩码、网关
netsh interface ipv4 set address "以太网" "static" "10.252.222.222" "255.255.255.0" "10.252.222.254"
netsh interface ipv4 set dnsservers name="以太网"static114.114.114.114
netsh interface ipv4 add dnsservers name="以太网" 223.5.5.5 index=2
echo 修改网卡Mac...
@set reg=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001
@set MAC=00E0707F55B0
@reg add "%reg%" /v NetworkAddress /t reg_SZ /d "%MAC%" /f
echo 设置完成
@set INTERFACE=以太网
echo 重启本机网卡...
netsh interface set interface "%INTERFACE%" disable
netsh interface set interface "%INTERFACE%" enable
pause
goto end
:end
exit
可以的,办公室电脑就是用脚本文件一键切换的,百度下就有
—— 来自 Xiaomi MI 6, Android 10上的 S1Next-鹅版 v2.2.2.1-alpha netsetman
用过一阵子,很方便。
bat也行但看到楼主来这里提问就说明水平有限了。
-- 来自 能看大图的 Stage1官方 Android客户端 有IP地址切换工具,也可以自己写个BAT放那里 本帖最后由 冰痕 于 2020-4-28 15:49 编辑
orecheng 发表于 2020-4-28 12:26
有,还包括修改MAC码。仅限WIN10,WIN7改改应该也能用,“以太网”是你的网卡
win10专业版,直接用管理员权限运行,出来错误提示
有参数错误,有不是可执行程序,我继续研究下吧
另外没办法显示中文是我系统的问题?
我曾经也用脚本的,直到发现了NetSetMan。。。 冰痕 发表于 2020-4-28 15:47
win10专业版,直接用管理员权限运行,出来错误提示
有参数错误,有不是可执行程序,我继续研究下吧
另外没 ...
我把参数调了下,你再看看?要根据自己的需要修改参数 网卡设置两个ip地址加一条路由就行了啊,为何搞那么麻烦 本帖最后由 冰痕 于 2020-4-28 22:45 编辑
alpha.h 发表于 2020-4-28 16:56
你们不用物理隔离的吗
嗯~~~不知道物理隔离具体怎么着
不过内网不允许接路由,所以没办法用2楼的办法,于是只能来回需要的时候插拔主机后面的网线后重新配置IP
楼上有说NetSetMan,我先试试 再装个网卡就完事了
页:
[1]