Created
October 21, 2021 19:12
-
-
Save Peterragheb/6cb966c055e85e90dd4de5f806eed165 to your computer and use it in GitHub Desktop.
OpenVPN Active Clients Tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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