Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Windows2000/XP/2003 > 巧用批处理实现windows xp/windows2003进程和端口关联
【标  题】:巧用批处理实现windows xp/windows2003进程和端口关联
【关键字】:windows,xp/windows2003
【来  源】:http://blog.chinaunix.net/article.php?articleId=33120&blogId=7486

巧用批处理实现windows xp/windows2003进程和端口关联

Your Ad Here

@ECHO OFF

set zhl_file=task_1$.txt
set zhl_temp_file=Temp1$.zhl
set zhl_file2=task_2$.txt
set zhl_temp_file2=Temp2$.zhl
set temp_1=lmj_zhl$.txt
set temp_2=lmj_zhl2$.txt
set zhl_1=%1
set zhl_2=2

作者: phanrider
--------------------------------------------------------------------------------
闲来无事的时候随手写了个,把它放在%SYSTEM%目录下,可省不少心-_-


@REM =====================
@REM = Write phanrider =
@REM = 2005.1.12 =
@REM =====================

@ECHO OFF

set zhl_file=task_1$.txt
set zhl_temp_file=Temp1$.zhl
set zhl_file2=task_2$.txt
set zhl_temp_file2=Temp2$.zhl
set temp_1=lmj_zhl$.txt
set temp_2=lmj_zhl2$.txt
set zhl_1=%1
set zhl_2=2


:BEGIN
if "%zhl_1%"=="" goto :HELP
if %zhl_1%==0 @echo 端口号不能为零!&& goto :END


if exist %zhl_file% erase %zhl_file%

if exist %zhl_temp_file% erase %zhl_temp_file%
echo 正在处理网络端口...
netstat -ano | find ":" >%zhl_file% 2>nul

for /f "eol=U tokens=1,2,3,4,5*" %%a in (%zhl_file%) do @echo %%a %%b$ %%c %%d #""%%e""# >> %zhl_temp_file% 2>nul

for /f "eol=T tokens=1,2,3,4*" %%a in (%zhl_file%) do @echo %%a %%b %%c * #""%%d""# >> %zhl_temp_file% 2>nul

if exist %zhl_file2% erase %zhl_file2%
if exist %zhl_temp_file2% erase %zhl_temp_file2%
echo 正在读取进程映像......

tasklist /FO CSV >%zhl_file2% 2>nul

echo 正在初始化映像和端口......
for /f "skip=2 tokens=1,2,3,4,5* delims=," %%a in (%zhl_file2%) do @echo %%a,#%%b#,%%c,%%d,%%e >> %zhl_temp_file2% 2>nul

echo 正在查找进程和端口对应关系......
if exist %temp_1% erase %temp_1%
type %zhl_temp_file% | find ":%zhl_1%$" >> %temp_1% 2>nul
for /f "tokens=4,5*" %%x in (%temp_1%) do @set zhl_2=%%y

if "%zhl_2%"=="2" echo 没有任何进程使用%zhl_1%端口 && goto :END

type %zhl_temp_file2% | find "%zhl_2%" >> %temp_2% 2>nul
for /f "tokens=1,2* delims=," %%f in (%temp_2%) do @set zhl_3=%%f

echo 发现进程%zhl_3%使用%zhl_1%端口


rem if exist Temp1.zhl erase Temp1.zhl
rem for /f "tokens=2,3*" %%i in (1.txt) do @echo %%j* >> Temp1.zhl

rem if exist Temp2.zhl erase Temp2.zhl
rem for /f "tokens=1,2* delims=:" %%j in (Temp1.zhl) do @echo %%k >> Temp2.zhl

REM echo %zhl_1%

REM type Temp1.zhl | find "%zhl_1%*" /N
goto :end

:HELP
echo WINXP/WIN2003查看指定端口是哪个进程使用
echo.
echo USE: %0 port

:END

REM ====================================
REM 最后的清扫工作
REM ====================================
erase %zhl_file% 1>nul 2>&1
erase %zhl_file2% 1>nul 2>&1
erase %zhl_temp_file% 1>nul 2>&1
erase %zhl_temp_file2% 1>nul 2>&1
erase %temp_1% 1>nul 2>&1
erase %temp_2% 1>nul 2>&1
set zhl_file=
set zhl_temp_file=
set zhl_file2=
set zhl_temp_file2=
set temp_1=

set zhl_1=
set zhl_2=

五种“网络钓鱼”实例解析及防范:【上一篇】
自制1080线高清WMV影片:【下一篇】
【相关文章】
  • 一个强大的杀windows进程命令ntsd
  • windows进程(超全)
  • Windows 2000 Server 实现磁盘的容错功能
  • Windows的自启动方式
  • Windows自动启动程序的查找
  • MS Windows Error Messages(错误信息)
  • windows取日期函数
  • windows常见问题解决二 (包括五个方面)
  • ASP 中经常调用到的Windows对象
  • 简要的Windows API函数大全
  • 【随机文章】
  • 从零开始学ASP.NET(基础篇)
  • 雷达扫描效果
  • 解析.Net框架下的XML编程技术
  • DB2 基础: 使用 DB2 数据移动实用工具中的文件类型修饰符
  • 流氓软件
  • Visual Basic 开发应用程序如何使用INI文件
  • 一个求质数的算法
  • 数据库安全性策略 (2)
  • UNIX 常用命令简介(5)
  • XPath语法
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.