List which VPN clients are connected

8

4

Situation: I have a private VPN server at home which is open to the internet so that a certain group of people can connect to it (only keypair authentication is allowed).

How can I see which clients are currently connected to my VPN server?

I already tried to ping the hosts but it seems like some (actually most of them) block ICMP requests, so this fails always. Of course, I could examine /etc/openvpn/openvpn.log every time but this is not very convenient and definitely not suitable for a status report sent via email to me.

Remark: I'm using OpenVPN 2.2.1 x86_64-linux-gnu.

MrD

Posted 2014-10-02T08:38:06.243

Reputation: 215

Answers

5

You can do this with a small expect-script:

#!/usr/bin/expect
spawn telnet localhost 7505
set timeout 10
expect "OpenVPN Management Interface"
send "status 3\r"
expect "END"
send "exit\r"

And run it with (e.g.)
while true; do ./openVPNUserlist.sh |grep -e ^CLIENT_LIST; sleep 1; done

Also, in your server.conf - file, add the line
management localhost 7505

Packages you need to have installed:
telnet expect

Interestingly, the status does only update after a while (when a client disconnects, it keeps being displayed in the status for quite a while... Did not find a way to get around this yet :(
Change the timeout in your server.conf to the values you need:
keepalive 10 60
= ping client every 10 seconds and consider it disconnected after 1 minute.

GoodbyeKitty

Posted 2014-10-02T08:38:06.243

Reputation: 66

1

I located extensive vpn logs in this folder:

ls /var/log/openvpn/

For me, there were two files there, named kind of like this:

Arbitary-Name-VPN.log
status-Arbitary-Name-VPN.log

The first file showed a log of all vpn connections that have happened over time, and the second one (status-...) showed who is connected right now.

LonnieBest

Posted 2014-10-02T08:38:06.243

Reputation: 1 099

0

The easy way is:

  • Add

    status /var/log/openvpn-status.log
    

    in your /etc/openvpn/server.conf and restart vpn server.

  • Use the below command to view connected clients from the log.

    while true;
    do
      cat /var/log/openvpn-status.log | sed -n '/OpenVPN CLIENT LIST/,/ROUTING TABLE/p' | tail -n+4 | sed "s/ROUTING TABLE//g";
      sleep 4s;
    done
    

    This will update the client list every 3 seconds.

James Arems

Posted 2014-10-02T08:38:06.243

Reputation: 3