List which VPN clients are connected
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops
--
Chapters
00:00 List Which Vpn Clients Are Connected
00:40 Accepted Answer Score 11
01:06 Answer 2 Score 2
01:28 Answer 3 Score 0
01:58 Answer 4 Score 0
02:14 Thank you
--
Full question
https://superuser.com/questions/819729/l...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#openvpn
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops
--
Chapters
00:00 List Which Vpn Clients Are Connected
00:40 Accepted Answer Score 11
01:06 Answer 2 Score 2
01:28 Answer 3 Score 0
01:58 Answer 4 Score 0
02:14 Thank you
--
Full question
https://superuser.com/questions/819729/l...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#openvpn
#avk47
ACCEPTED ANSWER
Score 11
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
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.
ANSWER 2
Score 2
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.
ANSWER 3
Score 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.
ANSWER 4
Score 0
If you want it done in a single bash script, I took @GoodbyeKitty answer and made a single script..
#!/bin/bash
function management_server() {
/usr/bin/expect <(cat << EOF
spawn telnet localhost 7505
set timeout 10
expect "OpenVPN Management Interface"
send "status 3\r"
expect "END"
send "exit\r"
EOF
)
}
while true
echo "Checking IPs"
do management_server | grep -e ^CLIENT_LIST
sleep 30
done