数学建模社区-数学中国
标题:
fport.vbs for XP/2003
[打印本页]
作者:
韩冰
时间:
2004-11-5 22:57
标题:
fport.vbs for XP/2003
<
>作者:zzzevazzz 来自:http://www.ph4nt0m.org</P>
; C3 s! I( K3 c5 b% m
<
>XP和2003下的netstat有-o选项,所以可以容易地实现fport。
! e/ y2 y3 \* a" ~2 h/ ]
. }/ i: i3 g1 {7 T- r& b7 [8 J$ ]
vbs脚本版:
: w9 _7 P0 r8 G
Codz:
" M6 V( T1 X, G7 h2 \) D+ Z& \
0 ]: r+ L/ S1 b( m. v# j) b
with new regexp
9 y: @* ?1 b( \ L" E1 \
.pattern="(..Ps+S+s+S+s+[A-Z]*)s*([0-9]+)"
% Z, Y* U' L! [5 |
.global=true
5 i; C8 g$ D2 X
set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)
4 e1 J4 ^, N5 k0 K% K9 D
end with
: g+ W/ m" `0 y* _/ L
for each ps in getobject("winmgmts:\.\rootcimv2:win32_process").instances_
4 Q# t( ]3 }/ l. r0 D
f=0
8 h) p! d6 o+ l# V5 G
for each m in ms
2 i6 [7 |7 Y! @; F7 D, j1 A2 N
if m.submatches(1)=ps.handle then
9 U* ^: Q5 a0 J) r; x' `6 m6 g
if f=0 then f=1:wscript.echo ">"&ps.handle&vbtab&ps.name&vbtab&ps.executablepath
2 h0 Z9 Z% b4 B3 o
wscript.echo " "&m.submatches(0)
- |5 Z6 p0 t6 u8 e o
end if
* l v7 V3 N. L" E
next
, q0 B% a A* V# T- l# [
next
4 j0 l2 L1 w/ D s- }* \9 `1 P. [
2 q, h( {, D) v; g4 g
; Z( F/ P+ S$ A4 b4 q
照例给出echo版,方便在远程shell中使用。
) @' x. k$ W, `3 I
@echo with new regexp:.pattern="(..P\s+\S+\s+\S+\s+[A-Z]*)\s*([0-9]+)":.global=true>fp.vbs
3 \7 R. \ A2 C4 J `7 z
@echo set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)>>fp.vbs
2 Q8 s7 f5 s w9 }& L
@echo end with:for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_>>fp.vbs
0 h, A8 R! r* J) \$ j- R; b
@echo f=0:for each m in ms:if m.submatches(1)=ps.handle then _>>fp.vbs
% F, F( Y! i* D$ I" w6 r
@echo if f=0 then f=1:wscript.echo ">"^&ps.handle^&vbtab^&ps.name^&vbtab^&ps.executablepath:end if:_>>fp.vbs
5 K) `% X( F) X- I E6 g& A
@echo wscript.echo " "^&m.submatches(0):end if:next:next>>fp.vbs
6 P/ I8 @) K% {
@cscript //nologo fp.vbs&del fp.vbs</P>
作者:
kensington
时间:
2010-2-3 23:20
排版好乱
作者:
sxjm567
时间:
2012-7-15 22:19
众里寻他千百度,蓦然回首在这里!
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5