Verbundene VNC-Clients anzeigen

  • Da ich immer wissen will, wer außer mir noch mittels VNC auf gewisse Rechner zugreift, habe ich mir heute folgendes Skript erstellt, das mir via netstat alle verbundenen PC's anzeigt. Das Skript starte ich auf den Rechnern, auf denen der VNC-Server läuft. Beenden mittels Strg+Alt+F10

    Viel Spaß! Hoffe es kann jemand brauchen.

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #Include <Array.au3>
    #Include <Misc.au3>
    #Include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('TrayMenuMode', 1)
    Opt('GUIEventOptions', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $title = 'VNC-Logger', $x = 80, $y = 25, $Label, $LabelHeight = 13, $aSave
    _Singleton($title)

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate($title, $x, $LabelHeight, @DesktopWidth - $x, $y, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetBkColor(0xFFFFDD)
    $Label = GUICtrlCreateLabel('', 0, 0, $x, $LabelHeight, 0x1)
    GUICtrlSetTip(-1, $title & @CRLF & 'Diese Computer sind derzeit online!')
    WinMove($title, '', Default, Default, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists(@ScriptDir & '\VNC-Logs') Then DirCreate(@ScriptDir & '\VNC-Logs')

    [/autoit] [autoit][/autoit] [autoit]

    _check()
    AdlibEnable('_check', 3000)
    HotKeySet('^!{F10}', '_Exit')
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _check()
    Local $sPC, $aPC = _GetConnectionFromPort()
    If UBound($aSave) <> UBound($aPC) Then
    $aSave = $aPC
    For $i = 0 To UBound($aPC) -1
    $sPC &= $aPC[$i] & @CRLF
    _FileWriteLog(@ScriptDir & '\VNC-Logs\VNC-Connections.log', 'Aktive Verbindung zu: ' & $aPC[$i])
    Next
    WinMove($title, '', Default, Default, $x, $LabelHeight*UBound($aPC), 100)
    If Not IsArray($aPC) Then _FileWriteLog(@ScriptDir & '\VNC-Logs\VNC-Connections.log', 'Keine Verbindungen mehr aktiv!')
    GUICtrlSetData($Label, $sPC)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetConnectionFromPort($sPort = '5900')
    ; funkey 17.06.2009
    ; gibt IP oder Namen eines verbundenen PC's abhängig vom Port zurück
    ; Standard-Port ist 5900 für VNC, 3389 wäre für Remotedesktop ('mstsc.exe')
    Local $sErgebnis, $aPort
    Local $pid = Run(@ComSpec & " /c " & 'netstat -np TCP |findstr ":'&$sPort&'"', "", @SW_HIDE, $STDOUT_CHILD)
    Do
    $sErgebnis &= StdoutRead($pid)
    Until @error
    $aPort = StringSplit($sErgebnis, @CRLF, 3)
    For $i = UBound($aPort) - 1 To 0 Step -1
    If StringInStr($aPort[$i], 'HERGESTELLT') Then
    $aPort[$i] = StringRegExpReplace($aPort[$i], '(\s+)(\S+)(\s+)(\S+)(\s+)(\S+):(\S+)(\s+)(\S+)', '$6')
    Else
    _ArrayDelete($aPort, $i)
    EndIf
    Next
    If Not IsArray($aPort) Then Return SetError(1, 0, "")
    Return $aPort
    EndFunc

    [/autoit]


    P.S. Ich weiß, es ist nicht perfekt, aber es läuft! Getestet auf WinXP SP2

    EDIT: Neue Version. Nun nennt sich das Ding VNC-Logger!

  • Jam00: Dann kannst du auch mal die neue Version testen!

    Spoiler anzeigen
    [autoit]

    ;~ #NoTrayIcon
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #Include <Array.au3>
    #Include <Misc.au3>
    #Include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('TrayMenuMode', 1)
    Opt('GUIEventOptions', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $title = 'VNC-Clients', $x = 80, $y = 25, $Label, $LabelHeight = 13, $aSave
    _Singleton($title)

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate($title, $x, $LabelHeight, @DesktopWidth - $x, $y, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetBkColor(0xFFFFDD)
    $Label = GUICtrlCreateLabel('', 0, 0, $x, $LabelHeight, 0x1)
    GUICtrlSetTip(-1, $title & @CRLF & 'Diese Computer sind derzeit online!')
    WinMove($title, '', Default, Default, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    _check()
    AdlibEnable('_check', 3000)
    HotKeySet('^!{F10}', '_Exit')
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _check()
    Local $sPC, $aPC = _GetConnectionFromPort()
    If UBound($aSave) <> UBound($aPC) Then
    $aSave = $aPC
    For $i = 0 To UBound($aPC) -1
    $sPC &= $aPC[$i] & @CRLF
    _FileWriteLog('VncVerbindungen.log', $aPC[$i])
    Next
    GUICtrlSetData($Label, $sPC)
    WinMove($title, '', Default, Default, $x, $LabelHeight*$i, 100)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetConnectionFromPort($sPort = '5900')
    ; funkey 17.06.2009
    ; gibt IP oder Namen eines verbundenen PC's abhängig vom Port zurück
    ; Standard-Port ist 5900 für VNC, 3389 wäre für Remotedesktop ('mstsc.exe')
    Local $sErgebnis, $aPort
    Local $pid = Run(@ComSpec & " /c " & 'netstat -np TCP |findstr ":'&$sPort&'"', "", @SW_HIDE, $STDOUT_CHILD)
    Do
    $sErgebnis &= StdoutRead($pid)
    Until @error
    $aPort = StringSplit($sErgebnis, @CRLF, 3)
    For $i = UBound($aPort) - 1 To 0 Step -1
    If StringInStr($aPort[$i], 'HERGESTELLT') Then
    $aPort[$i] = StringRegExpReplace($aPort[$i], '(\s+)(\S+)(\s+)(\S+)(\s+)(\S+):(\S+)(\s+)(\S+)', '$6')
    Else
    _ArrayDelete($aPort, $i)
    EndIf
    Next
    If Not IsArray($aPort) Then Return SetError(1, 0, "")
    Return $aPort
    EndFunc

    [/autoit]