本帖最后由 bbaa 于 2017-1-28 13:27 编辑
- @Rem Made By:Bbaa
- @Echo off
- @setlocal enabledelayedexpansion
- @Rem Demo
- :Begin
- Rem 获取ip地址.......
- Set IP=
- Set /p IP=请输入监视IP:
- Rem 监视端口列表
- Set 端口列表_计数=1
- For %%i In (
- "80"
- "8080"
- ) Do (Set "___端口列表___!端口列表_计数!=%%~i"&Set /a 端口列表_计数+=1)
- :Get_1
- Set Pid列表_计数=1
- Rem 获取java.exe Pid
- For /f "Tokens=1,2 Delims=:" %%i in ('Tasklist /FI "ImageName eq java.exe" /FO list') do (
- Rem 获取Pid
- If /i "%%~i"=="Pid" (
- Set "Pid=%%~i"
- Set "Pid=!Pid: =!"
- Set "___Pid列表___!Pid列表_计数!=!Pid!"
- Set /a Pid列表_计数+=1
- )
- )
- Rem 获取java.exe Pid End
- If Not Defined ___Pid列表___1 (Echo 貌似你没有运行java.exe +_+&PAUSE>nul&exit)
- Rem 获取端口列表
- set 显示列表_计数=1
- For /f "Tokens=1,3,5" %%i In ('Netstat -ano') Do (
- If /i "%%~i"=="TCP" (
- Rem 判断监视Ip
- If "!IP!"=="%%j" (
- For /f "Tokens=2 Delims=:" %%a In ("%%j") do (
- For /f "Tokens=2 Delims==" %%b In ('Set ___端口列表___') Do (
- If %%a==%%b (
- Rem 验证Pid
- For /f "Tokens=2 Delims==" %%c In ('Set ___Pid列表___') Do (
- If "%%k"=="%%c" (set "___显示列表___!显示列表_计数!=java.exe Pid:%%k 占用端口:%%b"&set /a 显示列表_计数+=1)
- )
- )
- )
- )
- )
- )
- )
- :Show
- If Defined ___显示列表___1 (
- For /f "Tokens=2 Delims==" %%b In ('Set ___显示列表___') Do (Echo;%%b)
- ) Else (echo java未连接端口)
- pause>nul&exit
复制代码 做完了O(∩_∩)O~~
PS:这贴还会有人么.......... |