Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor bandwidth usage ? #164

Open
lucydjo opened this issue Apr 3, 2023 · 3 comments
Open

Monitor bandwidth usage ? #164

lucydjo opened this issue Apr 3, 2023 · 3 comments

Comments

@lucydjo
Copy link

lucydjo commented Apr 3, 2023

Hello,
Is it possible to calculate the bandwidth usage?
I can't find anything about this in the documentation.

Thanks :)

@strangeh21
Copy link

strangeh21 commented Apr 17, 2023

Add verbose :)
pproxy -r socks5://{proxy['host']}:{proxy['port']}#{proxy['username']}:{proxy['password']} -l socks5://:{server_port} -vv

This prints out the current usage to stdout.
What I did is sent stdout to a class, and parsed the data.
Search for data_usage as such:

	class OutputHandler:
		def __init__(self):
			pass

		def write(self, message):
			self.parse_and_handle_output(message.strip())

		def flush(self):
			pass

		def print_to_output(self, message):
			print(message, file=sys.__stdout__)

		def parse_and_handle_output(self, output):
			websites = re.findall(r'->\s(?:.*)->\s(.*):\d+', output)
			data_usage = re.search(
				"DIRECT: \d+ \(([\d.]+[KM])/s,([\d.]+[KM])/s\)   PROXY: \d+ \(([\d.]+[KM])/s,([\d.]+[KM])/s\)",
				output)
			if websites:  # Parse the websites
				for website in websites:
					self.print_to_output(f"URL: {website}")
			elif data_usage and data_usage != "":  # Parse the data usage
				try:
					direct, direct2, proxy, proxy2 = data_usage.groups()
					direct_combined = self.to_megabytes(direct) + self.to_megabytes(direct2)
					proxy_combined = self.to_megabytes(proxy) + self.to_megabytes(proxy2)
					combined = float(direct_combined + proxy_combined)
					self.print_to_output(round(combined, 4))
			else:
				if output and output != "":
					self.print_to_output(output)

		@staticmethod
		def to_megabytes(value):
			if value[-1] == 'M':
				return float(value[:-1])
			elif value[-1] == 'K':
				return float(value[:-1]) / 1024
			else:
				return 0
sys.stdout = self.OutputHandler()

@maxiedaniels
Copy link

@strangeh21 Sorry, can you explain further? Are you running python proxy within a Python script? I'm running via command-line so I'm unclear on how I would adjust your solution.

@strangeh21
Copy link

@strangeh21 Sorry, can you explain further? Are you running python proxy within a Python script? I'm running via command-line so I'm unclear on how I would adjust your solution.

In short, verbose level 2 within commandline adds traffic logging. This is done by adding "-vv" When it is running you can press enter at any time to get a complete list of data usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants