数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-11-5 22:57
标题: fport.vbs for XP/2003
<>作者:zzzevazzz   来自:http://www.ph4nt0m.org</P>
# j% A: {5 [* O& C8 W<>XP和2003下的netstat有-o选项,所以可以容易地实现fport。6 |1 f) j+ R8 t" `

# L% u# S1 z& ~: |1 ^vbs脚本版:
- ^2 F, z  z( lCodz:
! s5 b' M$ [% a: R3 Y3 ]7 I) M/ x  M/ A7 A
with new regexp   \" y! \. |1 x9 D* x; t3 u
    .pattern="(..Ps+S+s+S+s+[A-Z]*)s*([0-9]+)"
- n; a* {3 s! l* E* q/ A* F3 d# b- q    .global=true 0 h- y; [" T4 c( P( ]: h0 |
    set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall) ) W( h1 b* W0 y
end with
& g. F! f+ U; ]- Rfor each ps in getobject("winmgmts:\.\rootcimv2:win32_process").instances_
3 B6 G7 S, U; u    f=0 0 r& I) S+ n' a! C' ?
    for each m in ms , r9 l% y0 s" D( C; Z
        if m.submatches(1)=ps.handle then
9 x4 |* e- N) ~) l1 ~            if f=0 then f=1:wscript.echo "&gt;"&amp;ps.handle&amp;vbtab&amp;ps.name&amp;vbtab&amp;ps.executablepath
( W0 H# U: X/ Y9 J. x  S            wscript.echo " "&amp;m.submatches(0)
% y8 V/ }% s; Z& _& a9 L4 T        end if
, O$ i- R6 C& a+ c% v. ]  L1 l% q    next ' h# E- |% A& r+ a( n% v8 H* M. J
next  w& e- ^$ p2 r0 A: r2 {

  x' w+ ~0 j6 c5 b9 V( M' U% q
2 q9 v; b( N6 k" B- {9 R照例给出echo版,方便在远程shell中使用。
! T" R* Z) ?8 }9 o& j  N@echo with new regexp:.pattern="(..P\s+\S+\s+\S+\s+[A-Z]*)\s*([0-9]+)":.global=true&gt;fp.vbs  j/ N1 j& |. i5 j+ x0 j* I* P
@echo set ms=.execute(createobject("wscript.shell").exec("netstat -ano").stdout.readall)&gt;&gt;fp.vbs
; J/ }/ d5 r; L8 k( s* x@echo end with:for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_&gt;&gt;fp.vbs( {6 J: B( v9 n. \/ K! [
@echo f=0:for each m in ms:if m.submatches(1)=ps.handle then _&gt;&gt;fp.vbs0 u4 e8 H# \5 K# S$ u0 {: R4 P
@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
/ {4 T- n, d8 V! r@echo wscript.echo " "^&amp;m.submatches(0):end if:next:next&gt;&gt;fp.vbs
$ `: ]5 u3 t) |. G, P2 L9 n& ^( P@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