Skip to content

Instantly share code, notes, and snippets.

@Peterragheb
Created October 21, 2021 19:12
Show Gist options
  • Save Peterragheb/6cb966c055e85e90dd4de5f806eed165 to your computer and use it in GitHub Desktop.
Save Peterragheb/6cb966c055e85e90dd4de5f806eed165 to your computer and use it in GitHub Desktop.
OpenVPN Active Clients Tracker
import datefinder
from hurry.filesize import size
from datetime import datetime
dateFormat = "%a %d/%m/%y %I:%M %p"
fromFormat = "%a %b %d %H:%M:%S %Y"
file = open("/var/log/openvpn/status.log", "r")
Lines = file.readlines()
date = next(datefinder.find_dates(Lines[1])).strftime(dateFormat)
print(date)
clients = []
for index, line in enumerate(Lines):
if index <= 2:
continue
if "ROUTING TABLE" in line.strip():
break
clients.append(line)
print("Connected Clients Count: {}".format(len(clients)))
for index, client in enumerate(clients):
values = client.split(",")
clientName = values[0]
realIP = values[1].split(":", 1)[0]
downloadSize = size(int(values[2]))
uploadSize = size(int(values[3]))
connectedSince = datetime.strptime(values[4].strip(),fromFormat).strftime(dateFormat)
print("Client {}/{}:\n\tClient Name: {}\n\tReal IP: {}\n\tDownload Size: {}\n\tUpload Size: {}\n\tConnected Since: {}".format(index+1, len(clients), clientName, realIP, downloadSize, uploadSize, connectedSince))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment