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.
ps -e