批处理查看本机IP配置信息及本机端口号占用情况
保存以下内容到chkLocalip.bat,可以查看本机IP配置情况
@echo off&echo. setlocal if /i "%*" == "/?" goto :HelpPrompt if /i "%*" == "-Help" goto :HelpPrompt set "nicstr=Index^,Name^,NetConnectionID^,Speed^" set "netstr=DefaultIPGateway^,DHCPEnabled^,DNSServerSearchOrder^,IPAddress^,IPSubnet^,MACAddress^" for /f "tokens=1,3-5 delims=,:" %%i in ('^ wmic nic where "Manufacturer<>'Microsoft' and NetConnectionStatus='2'" get %nicstr% /format:csv ^|^ findstr /v "^$ %nicstr:^=%" ^|^ findstr /n .*^ ') do ( echo.%%i. %%l, %%k setlocal EnableDelayedExpansion for /f "tokens=1-3 delims={}," %%a in ('wmic nicconfig where "Index='%%j'" get %netstr% /value ^| findstr /v "^$"') do ( set "%%a%%~b" for /f %%c in (%%c) do if /i "%%a" == "DNSServerSearchOrder=" set "DNSServerSearchOrder=!DNSServerSearchOrder!, %%~c" ) if "!DHCPEnabled:TRUE=!" == "!DHCPEnabled!" (echo.IPv4地址: !IPAddress! ^(手动^)) else echo.IPv4地址: !IPAddress! ^(自动^) echo.子网掩码: !IPSubnet! echo.默认网关: !DefaultIPGateway! echo.MAC 地址: !MACAddress! echo.DNS 地址: !DNSServerSearchOrder! endlocal echo. ) endlocal pause goto :eof :HelpPrompt echo.CheckIP [Version 1.0] - by Sonar echo.A command-line script to check network details goto :eof
保存以下内容到chkLocalPort.bat,可以查看本机端口号占用情况
@echo off&echo. setlocal set TCP_PID=<nul set UDP_PID=<nul set PID=<NUL if /i "%*" == "" goto :HelpPrompt if /i "%*" == "/?" goto :HelpPrompt if /i "%*" == "-Help" goto :HelpPrompt :TCP echo.-- TCP 端口 -- for /f "tokens=2-5" %%1 in ('netstat -ano ^| findstr /v "]:" ^| findstr "TCP" ^| findstr /r /c:":%1 *[0-9]"') do ( set "TCP_PID=%%4" echo.内^<--^>外: %%1 ^<==^> %%2 ^(%%3^) ) if not defined TCP_PID echo.TCP端口 %1 未被占用 echo. :UDP echo.-- UDP 端口 -- for /f "tokens=2-4" %%1 in ('netstat -ano ^| findstr /v "]:" ^| findstr "UDP" ^| findstr /c:":%1 "') do ( set "PID=%%3" echo.内^<--^>外: %%1 ^<==^> %%2 ) if not defined PID ( echo.UDP端口 %1 未被占用 if not defined TCP_PID goto :Quit set "PID=%TCP_PID%" ) echo. :Process echo.-- 进程服务 -- for /f "tokens=1-2,*" %%1 in ('tasklist -svc ^| findstr /c:" %PID% "') do ( echo.占用服务: %%3 echo.进程名称: %%1 ^(PID: %%2^) ) :Quit endlocal goto :eof :HelpPrompt echo.CheckPort [Version 1.0] - by Sonar echo.A command-line script to check local port status echo. echo. Usage: chkport ^<port^> goto :Quit
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/17371462.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!