数学建模社区-数学中国

标题: fport.vbs for XP/2003 [打印本页]

作者: 韩冰    时间: 2004-11-5 22:57
标题: fport.vbs for XP/2003
<>作者:zzzevazzz   来自:http://www.ph4nt0m.org</P>0 Z, H' Y* Y, m1 i: Q
<>XP和2003下的netstat有-o选项,所以可以容易地实现fport。
' |+ I# D8 H8 m; B; i- ?; U
) y& h, A6 Y. R/ cvbs脚本版:
8 r9 d3 F$ @9 k* q. a4 o$ ~Codz: . b' M( i$ _# {6 q

# M7 \4 K4 V+ u" D( _+ jwith new regexp   }" |8 {  i7 L1 \
    .pattern="(..Ps+S+s+S+s+[A-Z]*)s*([0-9]+)" 6 C6 g+ \( |$ I. g$ r2 b; _
    .global=true
4 r+ `- P- |2 \0 r* P    set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)
) U) m  k0 |) O3 d; Nend with
5 S# I' r3 F  n$ U& M/ _/ [. }for each ps in getobject("winmgmts:\.\rootcimv2:win32_process").instances_ 4 b. }% \9 D" e9 G% g( j/ n
    f=0
+ @) A9 v' r6 ?8 L( \    for each m in ms ! n' o: E; c7 J2 }6 o* X
        if m.submatches(1)=ps.handle then ) R$ S: Y( E8 L, q) M4 a
            if f=0 then f=1:wscript.echo "&gt;"&amp;ps.handle&amp;vbtab&amp;ps.name&amp;vbtab&amp;ps.executablepath
+ o- [* ~  P- ?            wscript.echo " "&amp;m.submatches(0)
3 J  {$ O- Z1 Y: X; I) z' N5 Z        end if ' q: ]  p5 A2 D* ?! ?) a
    next 8 f6 O3 B: ~; ?  x' J
next
+ m8 p) }( r. w4 m2 {0 N
5 n( C' J4 K3 R% h' n- V' M; e3 P3 a9 `. Y3 t% @0 G
照例给出echo版,方便在远程shell中使用。& A8 S0 x# E  |& A: s
@echo with new regexp:.pattern="(..P\s+\S+\s+\S+\s+[A-Z]*)\s*([0-9]+)":.global=true&gt;fp.vbs
4 Z- T% a2 t) S" ?+ {% ~@echo set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)&gt;&gt;fp.vbs( c' z% b5 k% W
@echo end with:for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_&gt;&gt;fp.vbs0 b/ ?: I  l# k# B
@echo f=0:for each m in ms:if m.submatches(1)=ps.handle then _&gt;&gt;fp.vbs
$ b% T+ y7 N2 }  N+ w" p" s2 V9 ^@echo if f=0 then f=1:wscript.echo "&gt;"^&amp;ps.handle^&amp;vbtab^&amp;ps.name^&amp;vbtab^&amp;ps.executablepath:end if:_&gt;&gt;fp.vbs( s; {, O( z. |+ g2 H6 {
@echo wscript.echo " "^&amp;m.submatches(0):end if:next:next&gt;&gt;fp.vbs
: I$ D6 T5 C# |, r: [@cscript //nologo fp.vbs&amp;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