6

I have an application that's running on an Ubuntu Server 14.04.3 using xsession and xorg with google-chrome. I've installed teamviewer 10 on the machine so if they have internet connection they can remotely log into the PC and edit the application's settings. What I want to do is to detect when a teamviewer session is being created (when someone logs into the PC) and after certain amount of time kick him out (which can be done by killing the Teamviewer process ID).

The thing is that I don't know how I can detect when a session starts with teamviewer. Is it possible doing such a thing?

2
  • @Rinzwind That's not it. They just mention how to kill the teamviewer process, however that's not my issue here. I need to tell when a session has begun and kill teamviewer 30 minutes after the session has begun.
    – kfirba
    Sep 25, 2015 at 10:30
  • Add the output of this command after a session has been started: ps -e
    – Daniel
    Oct 1, 2015 at 17:05

3 Answers 3

2
  • I have teamviewer 10 as a quick support version on my host machine.

    Teamviewer log file : ~/Desktop/TeamViewer/teamviewerqs/logfiles/TeamViewer10_Logfile.log

  • For full version: ~/.config/teamviewer10/logfiles/TeamViewer10_Logfile.log

So to detect the session you can watch this file using tail -f and the pattern *"==== .Open Desktop! ====". And once pattern is found , killing the required process after say 60 secs.

tail -f "$HOME/Desktop/TeamViewer/teamviewerqs/logfiles/TeamViewer10_Logfile.log" \
 | awk '/==== .*Open Desktop! ====/ { system("sleep 60 ; pkill -9 TeamViewer_Desktop") }'
0
0

I couldn't find any command line tool to check the current sessions. Also TeamViewer does not create new process for each new session.

I end up checking the created sockets directly using a modified script written by cYrus by from How to determine the socket connection up time on Linux

The script checks for established connections by teamviewerd daemon. It depends on the configuration but default, it tries port 5938 if it fails it tries 443 and may be 80. Then it prints out the life/up time in minutes of all sockets.

teamviewerd creates one connection when desktop application launched then another new one for session (I couldn't test multiple sessions)

#!/bin/bash

function suptime() {
    addr=${1:?Specify the remote IPv4 address}
    port=${2:?Specify the remote port number}
    pid=$(netstat -ntp 2>/dev/null | awk '
$6 == "ESTABLISHED" && $5 == "'$addr:$port'"\
{sub("/.*", "", $7); print $7}')
    hex_addr=$(python -c "
import socket, struct;
print hex(struct.unpack('<L',
socket.inet_aton('$addr'))[0])[2:10].upper().zfill(8)")
    hex_port=$(python -c "print hex($port)[2:].upper().zfill(4)")
    inode=$(awk '$3 == "'$hex_addr:$hex_port'" {print $10}' /proc/net/tcp)
    time=$(find /proc/$pid/fd -lname "socket:\[$inode\]" -printf %A@)
    LANG=C printf '%i' $(bc <<<"($(date +%s.%N) - $time)/60")
}

ns=$(netstat -tpn | grep -e ":5938 *ESTABLISHED *[0-9]*/teamviewerd" -e ":443 *ESTABLISHED *[0-9]*/teamviewerd" | awk '{print $5}')

for s in $ns
do

    addr=$(echo $s | awk '{split($0,a,":"); print a[1]};')
    port=$(echo $s | awk '{split($0,a,":"); print a[2]};')

    echo $(suptime $addr $port)
done

Other possible options:

  • Check log for connections like Amit did in his answer.
  • Use xdotool or similar tool, to open side panel them close session.
0

As of TeamViewer 12 and Ubuntu 16.04, a new process

/opt/teamviewer/tv_bin/TeamViever_Desktop --IPCport 5936 --module 1

is spawned with the start of the session. This can be easily monitored.

(I know this is an old question, but someone might find the update useful)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .