403Webshell
Server IP : 68.178.202.69  /  Your IP : 216.73.216.122
Web Server : Apache
System : Linux 69.202.178.68.host.secureserver.net 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64
User : ikioworld ( 1005)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/fm-agent/library/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/fm-agent/library//iperf3.py
import json
import logging
import os
import subprocess
import requests


class Iperf3Runner:
    default_start_url = "https://speed.fortisase.com/start_iperf"
    cached_start_info = None

    def __init__(self, iperf3_bin, start_url=None):
        if start_url is None:
            start_url = self.default_start_url
        self.start_url = start_url
        self.iperf_bin = iperf3_bin
        stat = os.stat(self.iperf_bin)
        perms = oct(stat.st_mode)[-3:]
        if "744" != perms:
            os.chmod(iperf3_bin, 0o744)
        self.log = logging.getLogger("Agent")

    def _fetch_info(self):
        if self.cached_start_info is not None:
            return self.cached_start_info
        r = requests.get(self.start_url, timeout=10)
        if 200 != r.status_code:
            raise Exception(f"Start_perf failure: {r.status_code}")
        self.cached_start_info = r.json()
        return self.cached_start_info

    def _run_test(self, iperf_args, response_key):
        p = subprocess.run(
            iperf_args, shell=True, capture_output=True, check=True, encoding="utf-8"
        )
        response = json.loads(p.stdout)
        bps = response["end"]["streams"][0][response_key]["bits_per_second"]
        metric_name = "download speed"
        if response_key == "sender":
            metric_name = "upload speed"
        self.log.info(
            "Metric {} args {} -> {} bits/s".format(metric_name, iperf_args, bps)
        )
        return bps

    def get_download_speed(self):
        info = self._fetch_info()
        args = "{} -c {} -p {} -t 10 -R --json".format(
            self.iperf_bin, info["ip"], info["upload_port"]
        )
        return self._run_test(iperf_args=args, response_key="receiver")

    def get_upload_speed(self):
        info = self._fetch_info()
        args = "{} -c {} -p {} -t 10 --json".format(
            self.iperf_bin, info["ip"], info["download_port"]
        )
        return self._run_test(iperf_args=args, response_key="sender")

Youez - 2016 - github.com/yon3zu
LinuXploit