显示ip的批处理

发布网友 发布时间:2022-04-22 00:30

我来回答

2个回答

热心网友 时间:2022-05-12 23:32

@echo off
setlocal enabledelayedexpansion
set isNetWork=0
for /f "tokens=1,2* delims=:" %%i in ('ipconfig /all') do (
echo %%i|findstr "以太网适配器">nul&&( for /f "tokens=1,2* delims= " %%x in ("%%i") do ( set interface=%%y ))&& set isNetWork=1
if "!isNetWork!"=="1" ( if not defined isDHCP ( echo %%i|findstr "DHCP 已启用">nul && set isDHCP=%%j && set isNetWork=0 ) )
if defined isDHCP (
if "!isDHCP:~1,-1!"=="否" (
echo 该IP是固定IP,不做任何修改&&pause&&exit
) else (
echo 修改IP中...
echo netsh interface ip set address "!interface:~0,-1!" static 192.168.0.11 255.255.255.0 192.168.0.1
echo pause&&exit
)
)
)

热心网友 时间:2022-05-13 00:50

以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
rem 将自动获取IP方式修改成固定IP
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "connection=本地连接"
set "ip=192.168.0.11"
set "subnet=255.255.255.0"
set "gateway=192.168.0.1"

set "Index="
set "DHCPEnabled="
for /f "delims=" %%a in ('wmic NIC where "NetConnectionID='%connection%'" get Index /value^|find "="') do set %%a
if not defined Index (echo;%connection% 不存在&pause&exit)
for /f "delims=" %%a in ('wmic NICCONFIG where "IPEnabled='TRUE' and Index='%Index%'" get DHCPEnabled /value^|find "="') do set %%a
if not defined DHCPEnabled (echo;%connection% 未连接&pause&exit)
if /i "%DHCPEnabled%" equ "FALSE" (echo;固定IP,不做任何修改&pause&exit)
netsh interface ip set address "%connection%" static %ip% %subnet% %gateway%||(echo;设置失败)
echo;%#% +%$%%$%/%@% %z%
pause
exit追问不好意思,前面那里忘记了还有一个要求:ip固定的话DNS也修改成192.168.0.1,应该往哪里填写?谢谢

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com