Jump to content

VNC-Logger


funkey
 Share

Recommended Posts

This script can log all incoming and outgoing VNC-connections.

Ctrl+Alt+F10 to close

Ctrl+Shift+F10 to show connected IP in a tooltip.

Have fun!

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

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

Global $title = 'VNC-Logger V2.0', $x = 200, $y = 25, $aSave, $sPC, $Visible = False
_Singleton($title)

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

HotKeySet('^!{F10}', '_Exit')
HotKeySet('^+{F10}', '_Visible')
TraySetToolTip($title & " : " & $Visible)
TCPStartup()
_check()
AdlibEnable('_check', 3000)

While 1
    Sleep(10000)
WEnd

Func _check()
    Local $PCName, $aPC = _GetConnectionFromPort()
    If UBound($aSave) <> UBound($aPC) Then
  $sPC = ""
        $aSave = $aPC
        For $i = 0 To UBound($aPC) -1
   $PCName = _TCPIpToName($aPC[$i])
            $sPC &= $aPC[$i] & ' (' & $PCName & ')' & @CRLF
            _FileWriteLog(@ScriptDir & '\VNC-Logs\VNC-Connections.log', 'Active connection to: ' & $aPC[$i] & ' (' & $PCName & ')')
        Next
  $sPC = StringTrimRight($sPC, 2)
  If $Visible Then ToolTip($sPC, @DesktopWidth - $x, $y, $title)
  If Not IsArray($aPC) Then  _FileWriteLog(@ScriptDir & '\VNC-Logs\VNC-Connections.log', 'No more connection active!')
    EndIf
EndFunc

Func _Exit()
TCPShutdown()
    Exit
EndFunc

Func _Visible()
$Visible = Not $Visible
If $Visible Then
  ToolTip($sPC, @DesktopWidth - $x, $y, $title)
Else
  ToolTip("")
EndIf
TraySetToolTip($title & " : " & $Visible)
EndFunc

Func _GetConnectionFromPort($sPort = '5900')
    ; funkey 17.06.2009
    ; returns IP of connected PC's depending on the port
    ; standard-port is 5900 for VNC
    Local $sErgebnis, $aPort, $sLang = StringRight(@OSLang, 2), $sInfo = "ESTABLISHED"
    Local $pid = Run(@ComSpec & " /c " & 'netstat -np TCP |findstr ":'&$sPort&'"', "", @SW_HIDE, $STDOUT_CHILD)
If $sLang = "07" Then $sInfo = "HERGESTELLT" ; german
    Do
        $sErgebnis &= StdoutRead($pid)
    Until @error
    $aPort = StringSplit($sErgebnis, @CRLF, 3)
    For $i = UBound($aPort) - 1 To 0 Step -1
        If StringInStr($aPort[$i], $sInfo) 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

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...