数学建模社区-数学中国
标题:
fport.vbs for XP/2003
[打印本页]
作者:
韩冰
时间:
2004-11-5 22:57
标题:
fport.vbs for XP/2003
<
>作者:zzzevazzz 来自:http://www.ph4nt0m.org</P>
% d7 [) V- x) V$ C, G2 {+ p
<
>XP和2003下的netstat有-o选项,所以可以容易地实现fport。
2 i) A4 a w! O1 Q. a
+ R; z: X) t! R0 S
vbs脚本版:
( z0 N" |4 O# M( A% \1 X
Codz:
7 D$ Z6 ~, G! l5 d' A# x Q
, P4 L1 ]7 P# s& @9 ?6 p
with new regexp
9 b3 W; a9 N, z- ~1 N
.pattern="(..Ps+S+s+S+s+[A-Z]*)s*([0-9]+)"
9 J) {& X) q# e$ h( d* [" f
.global=true
" C3 @$ s- i# s" n1 m3 U
set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)
. `4 H' @3 j! z4 A. K0 r7 x
end with
* H! Z5 O; {9 R; A( A
for each ps in getobject("winmgmts:\.\rootcimv2:win32_process").instances_
! `1 z# P1 Y) K, g$ T6 a4 V- n
f=0
$ j/ k: ]( d$ p: o3 \
for each m in ms
2 L+ _* a6 c2 v1 z: k$ c6 w& |
if m.submatches(1)=ps.handle then
1 K+ ~* |( x8 l" N) f" e7 @* ]6 i
if f=0 then f=1:wscript.echo ">"&ps.handle&vbtab&ps.name&vbtab&ps.executablepath
1 _3 s! t ~6 K4 E7 I
wscript.echo " "&m.submatches(0)
B/ o( n0 y+ Z1 j% K
end if
! W7 I- Q p* G/ l
next
! u# `: j8 m% D1 B6 r. V& c: B
next
$ v7 I1 }5 B# z ~* h: W. o
/ V0 T/ J" W |0 p8 d1 r+ V
" N% [: b3 c, B, Z, L6 e' _
照例给出echo版,方便在远程shell中使用。
$ D, ]" b/ Q* C: D* ~/ E
@echo with new regexp:.pattern="(..P\s+\S+\s+\S+\s+[A-Z]*)\s*([0-9]+)":.global=true>fp.vbs
. m( ?0 Q" ], l" m. y5 {
@echo set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)>>fp.vbs
d. k1 k+ r; L m+ [" \( z
@echo end with:for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_>>fp.vbs
# j; T: V8 S+ z% A y% Y7 u
@echo f=0:for each m in ms:if m.submatches(1)=ps.handle then _>>fp.vbs
1 U" X3 c5 s( b H0 g% E
@echo if f=0 then f=1:wscript.echo ">"^&ps.handle^&vbtab^&ps.name^&vbtab^&ps.executablepath:end if:_>>fp.vbs
; S) B+ G$ O! [
@echo wscript.echo " "^&m.submatches(0):end if:next:next>>fp.vbs
! Y. \2 [4 F2 u* O8 g
@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