Ergebnis 1 bis 11 von 11

Thema: Unitymedia Speedtest mit Python

  1. #1
    Mitglied Avatar von phre4k
    Registriert seit
    Mar 2015
    Beiträge
    5.463
    ngb:news Artikel
    4

    Unitymedia Speedtest mit Python

    Hi Leute,

    Ich hab folgendes Script:
    Code (Python):
    1. #!/usr/bin/env python3
    2. from splinter import Browser
    3. from time import sleep
    4. from urllib import parse
    5.  
    6. ### global variables
    7. answers = {}
    8. answers['plz'] = '12345'
    9. answers['provider'] = 'Unitymedia'
    10. answers['providerId'] = '450'
    11. answers['speed'] = '400 Mbit/s'
    12. answers['speedVal'] = '400000'
    13. answers['speedId'] = '53192'
    14. answers['tarif'] = '2play FLY 400'
    15. answers['tarifId'] = '53205'
    16.  
    17. ### do not change anything below this line
    18.  
    19. browser = Browser('chrome')
    20. browser.visit('https://breitbandmessung.de/test')
    21.  
    22. # click "start"
    23. print('Clicking start…')
    24. browser.find_by_css('.question-0 .button-blue-big-start').first.click()
    25. # wait a bit while the JS animation plays
    26. sleep(1)
    27.  
    28. # answer "Ja" to the question if you're using an Ethernet cable
    29. print('Answering that we\'re using a LAN cable…')
    30. browser.find_by_css('label[for="lan-ja"]').first.click()
    31. browser.find_by_css('.question-5 .button-blue-big-forward').first.click()
    32. sleep(1)
    33.  
    34. # answer "Ja" to the question whether you eliminated influence factors
    35. print('Answering that we eliminated influence factors…')
    36. browser.find_by_css('label[for="optimal-ja"]').first.click()
    37. browser.find_by_css('.question-10 .button-blue-big-forward').first.click()
    38. sleep(1)
    39.  
    40. # input Postleitzahl
    41. print('Filling PLZ…')
    42. browser.fill('plz', answers['plz'])
    43. browser.find_by_css('.question-20 .button-blue-big-forward').first.click()
    44. sleep(1)
    45.  
    46. #select provider (over ID)
    47. print('Filling provider…')
    48. browser.execute_script('$("#provider").val("'+answers['providerId']+'").trigger("chosen:updated");')
    49. browser.find_by_css('.question-30 .button-blue-big-forward').first.click()
    50. sleep(1)
    51.  
    52. # select speed (over ID)
    53. print('Filling speed…')
    54. browser.execute_script('$("#speed").val("'+answers['speedId']+'").trigger("chosen:updated");')
    55. browser.find_by_css('.question-40 .button-blue-big-forward').first.click()
    56. sleep(1)
    57.  
    58. # select tariff (over ID)
    59. print('Filling tariff…')
    60. browser.execute_script('$("#tarif").val("'+answers['tarifId']+'").trigger("chosen:updated");')
    61. browser.find_by_css('.question-50 .button-blue-big-forward').first.click()
    62. sleep(1)
    63.  
    64. # select "no limit" for download limits
    65. print('Selecting "no limit"…')
    66. browser.find_by_css('label[for="limit-nein"]').first.click()
    67. browser.find_by_css('.question-120 .button-blue-big-forward').first.click()
    68. sleep(1)
    69.  
    70. # start the test
    71. print('Starting the test…')
    72. browser.find_by_css('.question-60').find_by_text('5').first.click()
    73. browser.find_by_css('.question-60 .button-blue-big-forward').first.click()
    74. sleep(1)
    75.  
    76. # wait for completion
    77. print('Waiting…')
    78. if browser.is_text_present('Messung abgeschlossen', wait_time=70):
    79.   print('Measurement complete!')
    80. sleep(5)
    81.  
    82. # print results
    83. browser.execute_script('showdetails.click()')
    84.  
    85. results = {}
    86. results['download'] = browser.evaluate_script('$(".results-download .results-val").text()')
    87. results['upload'] = browser.evaluate_script('$(".results-upload .results-val").text()')
    88. results['ping'] = browser.evaluate_script('$(".results-ping .results-val").text()')
    89. results['id'] = browser.evaluate_script('$(".test-details .val-id").text()')
    90.  
    91. print(results)
    92.  
    Und folgendes Pipfile:
    Code (Python):
    1. [[source]]
    2.  
    3. url = "https://pypi.python.org/simple"
    4. verify_ssl = true
    5. name = "pypi"
    6.  
    7. [packages]
    8. splinter = "*"
    (Laufen lassen mit pipenv run python breitbandmessung.py3)

    Würde das jetzt gerne so umschreiben, dass das Script nicht mehr wild irgendwelche Buttons klickt, sondern die vom Speedtest intern verwendeten Variablen und .click-Funktionen nutzt (wie bei "print results" schon getan). Allerdings komme ich nicht an die Variablen im Array internal dran… Ich checke im JS-Code der Seite allerdings auch nicht, wo genau sie die internen Variablen löschen, sonst könnte man diese Funktion ja überschreiben bzw. überladen.
    *mit Linux wäre das natürlich nicht passiert™
    Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say. – Edward Snowden
    tilde.fun – dein kostenloser Linux-Account in der Cloud | Inoffizielle ngb-Telegram-Gruppe
    GCM/S/TW d s+:- a-----? C++$ UL+++$ P-- L+++ E---- W++++ !N ?K w- M-- !P[A-Z] Y++ PGP R* tv-- b++>++++ DI++\:\( G+ e+>++++ h*

  2. #2

    Re: Unitymedia Speedtest mit Python

    Wozu der Aufwand? Speedtest cli plus eine Zeile Crontab. Fertig.
    Für diesen Beitrag bedankt sich saddy

  3. #3
    Mitglied

    (Threadstarter)

    Avatar von phre4k
    Registriert seit
    Mar 2015
    Beiträge
    5.463
    ngb:news Artikel
    4

    Re: Unitymedia Speedtest mit Python

    Also mittlerweile haben sie den Speedtest erneuert und es gibt eine speedtest-api-2.3.7.js, Inhalt:

    Code:
    1.  
    2. var unitymedia = window.unitymedia || {};
    3. unitymedia.speedtest = unitymedia.speedtest || {};
    4. var currentSpeedtestId = currentSpeedtestId || null;
    5. (function(a, h) {
    6.     var k = 10;
    7.     a.init_done = !1;
    8.     a.ipv6 = null;
    9.     a.retry = {
    10.         download: !1,
    11.         upload: !1
    12.     };
    13.     a.is_ios = /(iPhone|iPod|iPad)/i.test(navigator.userAgent);
    14.     a.max_bytes_ios = 209715200;
    15.     a.provider_download = 0;
    16.     a.provider_upload = 0;
    17.     a.provider_ping = 0;
    18.     a.remote_port = null;
    19.     a.id = null;
    20.     a.helper = {};
    21.     a.timeSection = null;
    22.     a.timeStart = null;
    23.     a.download_streams = {};
    24.     a.upload_streams = {};
    25.     a.upload_xhr = new XMLHttpRequest;
    26.     a.bytes_loaded = {};
    27.     a.bytes_loaded_last_section = 0;
    28.     a.bytes_loaded_push = 0;
    29.     a.trigger_pingtimeout = null;
    30.     a.data = "0";
    31.     a.result = {
    32.         download_raw: [],
    33.         upload_raw: [],
    34.         ping_raw: [],
    35.         overall_time: [],
    36.         overall_bytes: [],
    37.         download: 0,
    38.         upload: 0,
    39.         ping: 0,
    40.         jitter: 0
    41.     };
    42.     a.detectIE = function() {
    43.         var a = window.navigator.userAgent,
    44.             c = a.indexOf("MSIE ");
    45.         if (0 < c) return parseInt(a.substring(c + 5, a.indexOf(".", c)), 10);
    46.         if (0 < a.indexOf("Trident/")) return c = a.indexOf("rv:"), parseInt(a.substring(c + 3, a.indexOf(".", c)), 10);
    47.         c = a.indexOf("Edge/");
    48.         return 0 < c ? parseInt(a.substring(c + 5, a.indexOf(".", c)), 10) : 0
    49.     };
    50.     a.init = function() {
    51.         a.init_ipv6()
    52.     };
    53.     a.init_ipv6 = function() {
    54.         var b = a.config.checkurl.replace(/\.speedtest/g,
    55.             "v6.speedtest") + "/empty.txt";
    56.         h.ajax({
    57.             url: b,
    58.             error: function(b) {
    59.                 a.ipv6 = !1;
    60.                 a.init_rpd()
    61.             },
    62.             success: function(b) {
    63.                 a.ipv6 = !0;
    64.                 a.config.checkurl = a.config.checkurl.replace(/\.speedtest/g, "v6.speedtest");
    65.                 a.init_sbc()
    66.             },
    67.             timeout: 2E3
    68.         })
    69.     };
    70.     a.init_sbc = function() {
    71.         h.ajax({
    72.             url: "/ajax/speedtest-init/",
    73.             contentType: "application/json",
    74.             dataType: "json",
    75.             data: {
    76.                 port: a.remote_port
    77.             },
    78.             error: function(b) {
    79.                 a.config.callback_error(20);
    80.                 a.log("SBC-Init (Error): " + JSON.stringify(b));
    81.                 a.track("init_sbc_error#" + currentSpeedtestId + "#Error: " + b)
    82.             },
    83.             success: function(b) {
    84.                 0 < b.downstreamSpeed && 0 < b.upstreamSpeed && (a.provider_download = b.downstreamSpeed, a.provider_upload = b.upstreamSpeed);
    85.                 currentSpeedtestId = b.speedtestId;
    86.                 a.config.callback_progress("init", {
    87.                     speedtest_id: b.speedtestId,
    88.                     downstream_init: b.downstreamSpeed,
    89.                     upstream_init: b.upstreamSpeed,
    90.                     downstream_booked: b.downstreamBooked,
    91.                     upstream_booked: b.upstreamBooked,
    92.                     isp: b.isp,
    93.                     clientIp: b.clientIp,
    94.                     modemType: b.modemType
    95.                 });
    96.                 a.init_done = !0;
    97.                 a.log("SBC-Init (Success): " + JSON.stringify(b));
    98.                 a.track("init_sbc_success#" +
    99.                     currentSpeedtestId + "#DownstreamSpeed: " + b.downstreamSpeed + ", UpstreamSpeed: " + b.upstreamSpeed + ", SpeedtestId: " + b.speedtestId + ", DownstreamBooked: " + b.downstreamBooked + ", UpstreamBooked: " + b.upstreamBooked + ", ISP: " + b.isp + ", ModemType: " + b.modemType)
    100.             },
    101.             timeout: 6E4
    102.         })
    103.     };
    104.     a.init_rpd = function() {
    105.         h.ajax({
    106.             url: "//rpd.speedtest.unitymedia.de/",
    107.             contentType: "application/json",
    108.             dataType: "json",
    109.             crossDomain: !0,
    110.             error: function(b) {
    111.                 a.config.callback_error(20);
    112.                 a.log("SBC-Init-Rpd (Error): " + JSON.stringify(b));
    113.                 a.track("init_rpd_error#" +
    114.                     currentSpeedtestId + "#Error: " + b)
    115.             },
    116.             success: function(b) {
    117.                 a.remote_port = b.port;
    118.                 a.init_sbc();
    119.                 a.log("SBC-Init-Rpd (Success): " + JSON.stringify(b));
    120.                 a.track("init_rpd_success#" + currentSpeedtestId + "#Port: " + b.port)
    121.             },
    122.             timeout: 5E3
    123.         })
    124.     };
    125.     a.run = function(b) {
    126.         switch (b) {
    127.             case "download":
    128.                 a.startDownload();
    129.                 break;
    130.             case "upload":
    131.                 a.startUpload();
    132.                 break;
    133.             case "ping":
    134.                 a.startPing()
    135.         }
    136.     };
    137.     a.transferEnd = function(b) {
    138.         a.getSectionSpeed()
    139.     };
    140.     a.transferEndWS = function(b) {
    141.         a.getSectionSpeedWS();
    142.         a.stopUploadTestWS()
    143.     };
    144.     a.stopDownloadTest = function() {
    145.         a.stopHandler &&
    146.             window.clearTimeout(a.stopHandler);
    147.         a.stopHandler = null;
    148.         for (var b = 0; 6 > b; b++) a.download_streams[b].req.abort();
    149.         a.running = null;
    150.         a.helper.result_from_arr(a.result.download_raw, "download", a.provider_download, a.result.overall_time.download, a.result.overall_bytes.download)
    151.     };
    152.     a.stopUploadTest = function() {
    153.         a.stopHandler && window.clearTimeout(a.stopHandler);
    154.         a.stopHandler = null;
    155.         a.upload_xhr.abort();
    156.         a.running = null;
    157.         a.helper.result_from_arr(a.result.upload_raw, "upload", a.provider_upload, a.result.overall_time.upload, a.result.overall_bytes.upload)
    158.     };
    159.     a.stopUploadTestWS = function() {
    160.         a.stopHandler && window.clearTimeout(a.stopHandler);
    161.         a.stopHandler = null;
    162.         a.socket.disconnect();
    163.         a.running = null;
    164.         a.helper.result_from_arr(a.result.upload_raw, "upload", a.provider_upload, a.result.overall_time.upload, a.result.overall_bytes.upload)
    165.     };
    166.     a.stopPingTest = function() {
    167.         null != a.running && (a.running = null, a.result.overall_time.ping = (new Date).getTime() - a.timeStart.getTime(), a.helper.result_from_arr(a.result.ping_raw, "ping", a.provider_ping, a.result.overall_time.ping, null), h("#runarea").removeAttr("src"))
    168.     };
    169.     a.getBytesUntilNow = function() {
    170.         var b = 0;
    171.         if ("download" == a.running)
    172.             for (var c = 0; 6 > c; c++) b += a.bytes_loaded[c];
    173.         "upload" == a.running && (b = a.bytes_loaded[0] + a.bytes_loaded_push);
    174.         return b
    175.     };
    176.     a.getSectionSpeed = function() {
    177.         var b = a.getBytesUntilNow(),
    178.             c = new Date,
    179.             e = b - a.bytes_loaded_last_section,
    180.             f = c.getTime() - a.timeSection.getTime(),
    181.             g = c.getTime() - a.timeStart.getTime(),
    182.             d = Math.round(8 * e / f);
    183.         a.result.overall_time[a.running] = g;
    184.         a.result.overall_bytes[a.running] = b;
    185.         0 < e && 0 < f && (a.timeSection = c, a.bytes_loaded_last_section = b, 375 <
    186.             f && ("download" == a.running && (c = g / 10 / k, a.result.download_raw.push(d), a.config.callback_progress("download_im_result", d), a.is_ios && b > a.max_bytes_ios && (a.config.callback_progress("statusbar", 100), a.stopDownloadTest()), a.config.callback_progress("statusbar", c)), "upload" == a.running && (c = g / 10 / 10, a.result.upload_raw.push(d), a.config.callback_progress("upload_im_result", d), a.config.callback_progress("statusbar_reverse", c))))
    187.     };
    188.     a.getSectionSpeedWS = function() {
    189.         var b = a.getBytesUntilNow(),
    190.             c = a.timestamp_push,
    191.             e = b -
    192.             a.bytes_loaded_last_section,
    193.             f = c - a.timeSectionWS,
    194.             g = c - a.timeStartWS,
    195.             d = Math.round(8 * e / f);
    196.         a.result.overall_time[a.running] = g;
    197.         a.result.overall_bytes[a.running] = b;
    198.         0 < e && 0 < f && (a.timeSectionWS = c, a.bytes_loaded_last_section = b, 375 < f && "upload" == a.running && (b = g / 10 / 10, a.result.upload_raw.push(d), a.config.callback_progress("statusbar_reverse", b)))
    199.     };
    200.     a.log = function(a) {};
    201.     a.track = function(a) {};
    202.     a.startDownload = function() {
    203.         if (null == a.running) {
    204.             a.running = "download";
    205.             a.config.callback_progress("download_start");
    206.             for (var b =
    207.                     a.bytes_loaded_last_section = 0; 6 > b; b++) a.bytes_loaded[b] = 0, a.download_streams[b] = {
    208.                     url: a.config.checkurl + "/data.zero.bin.256M?" + Math.random(),
    209.                     req: new XMLHttpRequest,
    210.                     updateProgress: function(b) {
    211.                         a.bytes_loaded[this.id] = b.loaded
    212.                     }
    213.                 }, a.download_streams[b].req.id = b, a.download_streams[b].req.open("GET", a.download_streams[b].url, !0), a.download_streams[b].req.onprogress = a.download_streams[b].updateProgress, a.download_streams[b].req.onload = a.transferEnd, a.download_streams[b].req.onerror = a.transferEnd, a.download_streams[b].req.onabort =
    214.                 a.transferEnd, a.download_streams[b].req.responseType = "blob";
    215.             a.helper.interval(a.getSectionSpeed, 750, a.helper.intervalRoundTrips(k, 750));
    216.             "number" === typeof a.stopHandler && (a.log("resetting Timeout download"), window.clearTimeout(a.stopHandler), a.stopHandler = null);
    217.             a.stopHandler = window.setTimeout(a.stopDownloadTest, 1E3 * k);
    218.             a.timeStart = new Date;
    219.             a.timeSection = a.timeStart;
    220.             for (b = 0; 6 > b; b++) a.download_streams[b].req.send();
    221.             a.track("start_download#" + currentSpeedtestId + "#TimeStart: " + a.timeStart)
    222.         }
    223.     };
    224.     a.pushData =
    225.         function() {
    226.             var b = a.config.checkurl + "/empty.txt";
    227.             a.bytes_loaded_push = 0;
    228.             a.upload_xhr.open("POST", b, !0);
    229.             a.upload_xhr.onerror = a.transferEnd;
    230.             a.upload_xhr.onabort = a.transferEnd;
    231.             a.upload_xhr.onload = function() {
    232.                 a.bytes_loaded[0] += a.bytes_loaded_push;
    233.                 a.bytes_loaded_push = 0;
    234.                 a.pushData()
    235.             };
    236.             a.upload_xhr.contentType = "application/octet-stream";
    237.             a.upload_xhr.responseType = "blob";
    238.             a.upload_xhr.upload.onprogress = function(b) {
    239.                 a.bytes_loaded_push = b.loaded
    240.             };
    241.             a.upload_xhr.send(a.data)
    242.         };
    243.     a.pushDataWS = function() {
    244.         a.bytes_loaded_last_section =
    245.             0;
    246.         a.bytes_loaded[0] = 0;
    247.         a.bytes_loaded_push = 0;
    248.         a.timeStartWS = null;
    249.         a.socket = io(a.config.checkurl, {
    250.             secure: !0,
    251.             path: "/upload/socket.io"
    252.         }).connect();
    253.         var b = new SocketIOFileUpload(a.socket);
    254.         b.chunkSize = 262144;
    255.         b.addEventListener("complete", function(c) {
    256.             a.bytes_loaded[0] += a.bytes_loaded_push;
    257.             a.bytes_loaded_push = 0;
    258.             a.bytes_loaded_last_section = 0;
    259.             b.submitFiles([a.helper.generateFile()])
    260.         });
    261.         a.socket.addEventListener("error", a.transferEndWS);
    262.         a.socket.on("upload.start", function(b) {
    263.             null == a.timeStartWS && (a.timeStartWS =
    264.                 b.start);
    265.             a.timeSectionWS = a.timeStartWS
    266.         });
    267.         a.socket.on("upload.progress", function(b) {
    268.             a.bytes_loaded_push = b.bytesProcessed;
    269.             a.timestamp_push = b.timeStamp
    270.         });
    271.         a.socket.on("upload.done", function(a) {});
    272.         b.submitFiles([a.helper.generateFile()])
    273.     };
    274.     a.startUpload = function() {
    275.         if (null == a.running) {
    276.             a.running = "upload";
    277.             a.data = "0";
    278.             for (var b = 0; 9999999 > b; b++) a.data += "0";
    279.             15 > a.detectIE() && (a.data += a.data);
    280.             a.config.callback_progress("upload_start");
    281.             a.bytes_loaded_last_section = 0;
    282.             a.bytes_loaded[0] = 0;
    283.             a.helper.interval(a.getSectionSpeed,
    284.                 1E3, a.helper.intervalRoundTrips(10, 1E3));
    285.             "number" === typeof a.stopHandler && (a.log("resetting Timeout upload"), window.clearTimeout(a.stopHandler), a.stopHandler = null);
    286.             a.stopHandler = window.setTimeout(a.stopUploadTest, 1E4);
    287.             a.timeStart = new Date;
    288.             a.timeSection = a.timeStart;
    289.             a.pushData();
    290.             a.track("start_upload#" + currentSpeedtestId + "#TimeStart: " + a.timeStart)
    291.         }
    292.     };
    293.     a.startUploadWS = function() {
    294.         if (null == a.running) {
    295.             a.running = "upload";
    296.             a.data = "0";
    297.             for (var b = 0; 9999999 > b; b++) a.data += "0";
    298.             a.config.callback_progress("upload_start");
    299.             a.helper.interval(a.getSectionSpeedWS, 1E3, a.helper.intervalRoundTrips(10, 1E3));
    300.             "number" === typeof a.stopHandler && (a.log("resetting Timeout uploadWS"), window.clearTimeout(a.stopHandler), a.stopHandler = null);
    301.             a.stopHandler = window.setTimeout(a.transferEndWS, 1E4);
    302.             a.pushDataWS();
    303.             a.track("start_upload_ws#" + currentSpeedtestId + "#TimeStart: " + a.timeStart)
    304.         }
    305.     };
    306.     a.startPing = function() {
    307.         a.config.callback_progress("ping_start");
    308.         a.timeStart = new Date;
    309.         a.running = "ping";
    310.         h("#runarea").attr("src", a.config.pingurl + "/rtt/");
    311.         "number" === typeof a.stopHandler && (a.log("resetting Timeout ping"), window.clearTimeout(a.stopHandler), a.stopHandler = null);
    312.         a.stopHandler = window.setTimeout(a.stopPingTest, 8E3);
    313.         h(window).on("message", function(b) {
    314.             b = b.originalEvent.data; - 1 == b ? (window.clearTimeout(a.stopHandler), a.stopHandler = null, a.stopPingTest()) : (a.result.ping_raw.push(b), a.config.callback_progress("ping_im_result", b))
    315.         });
    316.         a.track("start_ping#" + currentSpeedtestId + "#TimeStart: " + a.timeStart)
    317.     };
    318.     a.check_error = function(b) {
    319.         a.status.running = 1;
    320.         a.config.callback_error(b)
    321.     };
    322.     a.helper.result_from_arr = function(b, c, e, f, g) {
    323.         h.ajax({
    324.             url: "/ajax/result/",
    325.             cache: !1,
    326.             dataType: "json",
    327.             method: "POST",
    328.             data: {
    329.                 values: b,
    330.                 type: c,
    331.                 ref: e,
    332.                 time: f,
    333.                 bytes: g
    334.             },
    335.             success: function(b) {
    336.                 switch (b.type) {
    337.                     case "download":
    338.                         a.result.download = b.value;
    339.                         0 == parseInt(b.value, 10) ? 0 == a.retry.download ? (a.log("second download test"), a.retry.download = !0, k = 5, a.startDownload()) : a.config.callback_error(500) : (a.config.callback_progress("download_finished", a.result.download), window.setTimeout(function() {
    340.                                 a.run("upload")
    341.                             },
    342.                             500));
    343.                         break;
    344.                     case "upload":
    345.                         a.result.upload = b.value;
    346.                         a.config.callback_progress("upload_finished", a.result.upload);
    347.                         window.setTimeout(function() {
    348.                             a.run("ping")
    349.                         }, 500);
    350.                         break;
    351.                     case "ping":
    352.                         a.result.ping = b.value, a.result.jitter = b.jitter, a.config.callback_progress("ping_finished", a.result.ping), window.setTimeout(function() {
    353.                             a.config.callback_progress("finished")
    354.                         }, 500)
    355.                 }
    356.             }
    357.         })
    358.     };
    359.     a.helper.median = function(b) {
    360.         b = b.sort(a.helper.sortNumber);
    361.         var c = b.length;
    362.         return 0 == c % 2 ? (c /= 2, (parseFloat(b[c - 1]) + parseFloat(b[c])) / 2) : b[(c -
    363.             1) / 2]
    364.     };
    365.     a.helper.sum_array = function(a) {
    366.         for (var b = 0, e = 0; e <= a.length - 1; e++) b += a[e];
    367.         return b
    368.     };
    369.     a.helper.sortNumber = function(a, c) {
    370.         return a - c
    371.     };
    372.     a.helper.f = function(b) {
    373.         return 0 == b ? 1 : 1 == b ? 1 : b * a.f(b - 1)
    374.     };
    375.     a.helper.generateFile = function() {
    376.         var b = Math.random(),
    377.             c = new File([a.data], "empty" + b + ".txt", {
    378.                 type: "application/octet-stream"
    379.             });
    380.         a.log("file.name: empty." + b + ".txt, _$.data payload size: " + c.size);
    381.         return c
    382.     };
    383.     a.helper.interval = function(b, c, e) {
    384.         var f = function(c, d) {
    385.             return function() {
    386.                 if ("undefined" === typeof d || 0 < d--) {
    387.                     setTimeout(f,
    388.                         c);
    389.                     try {
    390.                         b.call(null), a.log("interval: #" + d + " @" + new Date)
    391.                     } catch (l) {
    392.                         throw d = 0, l.toString();
    393.                     }
    394.                 }
    395.             }
    396.         }(c, e);
    397.         setTimeout(f, c)
    398.     };
    399.     a.helper.intervalRoundTrips = function(a, c) {
    400.         return Math.round(1E3 * a / c) + 1
    401.     };
    402.     a.helper.generateFile = function() {
    403.         var b = Math.random(),
    404.             c = new File([a.data], "empty" + b + ".txt", {
    405.                 type: "application/octet-stream"
    406.             });
    407.         a.log("file.name: empty." + b + ".txt, _$.data payload size: " + c.size);
    408.         return c
    409.     };
    410.     a.helper.interval = function(b, c, e) {
    411.         var f = function(c, d) {
    412.             return function() {
    413.                 if ("undefined" === typeof d || 0 < d--) {
    414.                     setTimeout(f,
    415.                         c);
    416.                     try {
    417.                         b.call(null), a.log("interval: #" + d + " @" + new Date)
    418.                     } catch (l) {
    419.                         throw d = 0, l.toString();
    420.                     }
    421.                 }
    422.             }
    423.         }(c, e);
    424.         setTimeout(f, c)
    425.     };
    426.     a.helper.intervalRoundTrips = function(a, c) {
    427.         return Math.round(1E3 * a / c) + 1
    428.     }
    429. })(unitymedia.speedtest || {}, jQuery);
    Diese lädt folgende Datei herunter: https://speedtest-01v6.speedtest.uni...48329799340821

    Hinter dem Fragezeichen steht eine zufällige Nummer, vermutlich um Caching zu vermeiden. Wie setze ich das jetzt als Speedtest-CLI um?

    EDIT: Schneller Speedtest mit Bash:
    Code (Bash):
    1. curl https://speedtest-01v6.speedtest.unitymedia.de/data.zero.bin.256M -o /dev/null -w '%{speed_download}' | sed 's/,[0-9]*/\/1024\n/' | bc
    Output ist die Durchschnittsgeschwindigkeit in KiB/s.
    Geändert von phre4k (02.06.19 um 01:27 Uhr)
    *mit Linux wäre das natürlich nicht passiert™
    Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say. – Edward Snowden
    tilde.fun – dein kostenloser Linux-Account in der Cloud | Inoffizielle ngb-Telegram-Gruppe
    GCM/S/TW d s+:- a-----? C++$ UL+++$ P-- L+++ E---- W++++ !N ?K w- M-- !P[A-Z] Y++ PGP R* tv-- b++>++++ DI++\:\( G+ e+>++++ h*

  4. #4

    Re: Unitymedia Speedtest mit Python

    @phre4k: Was ich schon mal sagen kann, die Nummer ist "random", siehe hier:
    Code (JavaScript):
    1. url: a.config.checkurl + "/data.zero.bin.256M?" + Math.random(),
    Das heißt du kannst theoretisch irgend eine Zahl <= 1.0 nehmen - diese wird an a.config.checkurl/data.zero.bin.256M? angefügt.

    Was ist denn deine Frage, wie du das mit CURL oder wget realisieren kannst?
    Naja, für den Download einfach die URL ansprechen.

    Was nicht klar ist, was "a.config.checkurl" ist, das steht nicht in deinem Quelltext, aber anhand der URL und das "v6.speedtest" = IPV6 mit "replace" ersetzt wird in der URL:
    IPV4:
    Code (Text):
    1. https://speedtest-01.speedtest.unitymedia.de/data.zero.bin.256M?
    IPV6:
    Code:
    1. https://speedtest-01v6.speedtest.unitymedia.de/data.zero.bin.256M?
    Code (JavaScript):
    1.   var b = a.config.checkurl.replace(/\.speedtest/g, "v6.speedtest")
    Also wird die a.config.checkurl Basis so aussehen:
    Code (Text):
    1. https://speedtest-01.speedtest.unitymedia.de
    Hier könnte "-01" der jeweilige Server sein.

    Also am Ende so mit CURL:
    Code (Text):
    1. curl -o https://speedtest-01.speedtest.unitymedia.de/data.zero.bin.256M?0.1234567 > data.zero.bin.256M
    Geändert von theSplit (02.06.19 um 01:59 Uhr)
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  5. #5
    Mitglied

    (Threadstarter)

    Avatar von phre4k
    Registriert seit
    Mar 2015
    Beiträge
    5.463
    ngb:news Artikel
    4

    Re: Unitymedia Speedtest mit Python

    Wäre halt cool, wenn ich ein Script schreiben könnte, was den Unitymedia-Speedtest nutzt und die Speedtest-ID und die anderen Werte ausgeben kann.

    Dummerweise will Unitymedia von Speed-Problemen nämlich nie was wissen, wenn man nicht deren hauseigenen Speedtest nutzt.

    Breitbandmessung.de bietet leider auch keine API an :/

    Zitat Zitat von info@breitbandmessung.de
    Die Bundesnetzagentur hat Kriterien zur Bestimmung einer nicht vertragskonformen Leistung bei Breitband-Festnetzanschlüssen im Download festgelegt. Die Kriterien können Sie der Mitteilung Nr. 485/2017 der Bundesnetzagentur entnehmen. Die Mitteilung ist unter dem folgenden Link abrufbar: http://www.bundesnetzagentur.de/brei...chwindigkeiten.

    die Bereitstellung einer API zur Nutzung der Breitbandmessung ist nicht in Planung. Für diesen Zweck wird die Breitbandmessung Desktop-App zur Verfügung gestellt, um die von der Bundesnetzagentur festgelegten Kriterien für einen Nutzer ein einfacher Form abbilden zu können.

    Die installierbare Desktop-App befindet sich derzeit in der Entwicklung und soll in Kürze veröffentlicht werden. Mit der Desktop-App können Messkampagnen durchgeführt und Messprotokoll generiert werden.

    Die Anwendung wird für Windows, MacOS und Linux bereitgestellt.
    *mit Linux wäre das natürlich nicht passiert™
    Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say. – Edward Snowden
    tilde.fun – dein kostenloser Linux-Account in der Cloud | Inoffizielle ngb-Telegram-Gruppe
    GCM/S/TW d s+:- a-----? C++$ UL+++$ P-- L+++ E---- W++++ !N ?K w- M-- !P[A-Z] Y++ PGP R* tv-- b++>++++ DI++\:\( G+ e+>++++ h*

  6. #6

    Re: Unitymedia Speedtest mit Python

    @phre4k: Just in diesem Moment sehe ich da kein Problem so etwas umzusetzen. Du willst das als Python Skript, oder Bash schreiben?

    Was ich spontan sehe:
    1) JSON kommt drin vor, muß also geschrieben/gelesen werden können
    2) Dateien müssen generiert werden a.data für den Upload
    3) Curl mit Binding oder requests? Beispiel Python mit pyCurl/requests (Und mehr hier)
    Geändert von theSplit (02.06.19 um 02:47 Uhr) Grund: *added mehr
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  7. #7

    Re: Unitymedia Speedtest mit Python

    Ich hab dir mal was zusammengeschrieben @ phre4k:

    Das behandelt aber nur den Download, nicht den Upload, Python3 und pyCurl vorausgesetzt.

    Code (Python):
    1. #entfernt
    Siehe https://ngb.to/threads/32596-Unityme...393#post941393
    Geändert von theSplit (03.06.19 um 08:42 Uhr) Grund: Min, Max, Average entfernt, da curl Flushing nicht aktuelle Daten
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  8. #8

    Cool Re: Unitymedia Speedtest mit Python

    Hab das Skript etwas verbessert, mit geringster Geschwindigkeit, maximaler Geschwindigkeit und durchschnittlicher Geschwindigkeit.

    Code (Python):
    1. #entfernt
    Siehe https://ngb.to/threads/32596-Unityme...393#post941393
    Geändert von theSplit (03.06.19 um 08:43 Uhr) Grund: Fixing max download display
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  9. #9

    Cool Re: Unitymedia Speedtest mit Python

    Hier jetzt Download und Upload in einem:

    speedtest.py # (default) Download + Upload Tests
    speedtest.py -u # Upload
    speedtest.py -d # Download
    speedtest.py -u -d # Upload + Download

    Code (Python):
    1.  
    2. #!/usr/bin/env python3
    3. import sys
    4. import random
    5. import time
    6. from os import path, remove
    7.  
    8. import pycurl
    9.  
    10.  
    11. # Download size in MB, can be power of 8
    12. dlSize = 256
    13.  
    14. # URI
    15. baseURI = 'https://speedtest-01.speedtest.unitymedia.de'
    16. baseURIipv6 = 'https://speedtest-01v6.speedtest.unitymedia.de'
    17. baseDownload = '/data.zero.bin.' + str(dlSize) + 'M'
    18.  
    19. # ------------------------------------------------------------------------
    20. random.seed(time.time())
    21. randomComponent = random.random()
    22.  
    23. # ------------------------------------------------------------------------
    24. def downloadSpeedTest():
    25.     global dlSize, blockSize
    26.     speedCollection = [0]
    27.     downloadURL = baseURI + baseDownload + '?' + str(randomComponent)
    28.     downloadData = []
    29.     downloadSize = dlSize * (1024 * 1024)
    30.     blockSize = 0
    31.     blockStepSize = downloadSize / 100
    32.  
    33.     def writeLoop(data):
    34.         global blockSize
    35.         blockSize += len(data)
    36.         if blockSize >= blockStepSize:
    37.             print('.', end='', flush=True)
    38.             blockSize -= blockStepSize
    39.  
    40.         downloadData.append(data)
    41.  
    42.     def writeProgress(dlTotal, dlNow, ulTotal, ulNow):
    43.         if speedCollection[len(speedCollection) - 1] != dlNow:
    44.             speedCollection.append(dlNow)
    45.  
    46.     print('Starting download of URI: \'%s\'\n' % downloadURL)
    47.     c = pycurl.Curl()
    48.     c.setopt(c.URL, downloadURL)
    49.     c.setopt(c.USERAGENT, 'curl')
    50.     c.setopt(c.VERBOSE, False)
    51.     c.setopt(c.USE_SSL, True)
    52.     c.setopt(c.ENCODING, 'utf-8')
    53.     c.setopt(c.WRITEFUNCTION, writeLoop)
    54.     c.setopt(c.PROGRESSFUNCTION, writeProgress)
    55.     c.setopt(c.NOPROGRESS, False)
    56.     c.perform()
    57.  
    58.     dlName = path.basename(baseDownload)
    59.     dlSpeed = c.getinfo(c.SPEED_DOWNLOAD) / 1000.0 / 1000.0
    60.     dlSize = c.getinfo(c.SIZE_DOWNLOAD)
    61.     dlTime = c.getinfo(c.TOTAL_TIME)
    62.  
    63.     speedCollection = speedCollection[1:]
    64.     speedCollection.reverse()
    65.     speedCollection = speedCollection[1:]
    66.  
    67.     speedMin = speedCollection[0]
    68.     speedMax = speedCollection[0]
    69.     speedTotal = 0
    70.  
    71.     for index, item in enumerate(speedCollection):
    72.         try:
    73.             speed = item - speedCollection[index + 1]
    74.         except:
    75.             break
    76.  
    77.         if speed < speedMin:
    78.             speedMin = speed
    79.         if speed > speedMax:
    80.             speedMax = speed
    81.         speedTotal += speed
    82.  
    83.     speedMin = speedMin / 1024.0
    84.     speedMax = speedMax / 1024.0
    85.     speedAverage = speedTotal / len(speedCollection)
    86.  
    87.     print('\n\nFinished downloading \'%s\', %d bytes ( %.3f MB)\n\nAverage speed of %.3f MiB\n[MIN: %.3f KB ::: MAX: %.3f Kb ::: AVG: %.3f KB]\n\nMeasured in %d minutes and %d seconds (%.3f seconds total)\n\n' % (
    88.         dlName, dlSize, dlSize / 1024.0 / 1024.0, dlSpeed, speedMin, speedMax * 2.0, speedAverage, dlTime / 60, dlTime % 60.0, dlTime))
    89.  
    90.     c.close()
    91.  
    92. # ------------------------------------------------------------------------
    93.  
    94. def uploadSpeedtest():
    95.     speedCollection = [0]
    96.     ulName = 'empty.txt'
    97.     uploadURI = baseURI + '/empty.txt'
    98.     uploadData = "0" * (10000000 * 2)
    99.  
    100.     with open(ulName, 'w') as uploadFile:
    101.         uploadFile.write(uploadData)
    102.  
    103.     ulSize = len(uploadData)
    104.  
    105.     def readProgress(dlTotal, dlNow, ulTotal, ulNow):
    106.         if speedCollection[len(speedCollection) - 1] != ulNow:
    107.             speedCollection.append(ulNow)
    108.  
    109.     print('Starting upload of URI: \'%s\'\n' % uploadURI)
    110.  
    111.     c = pycurl.Curl()
    112.     c.setopt(c.URL, uploadURI)
    113.     c.setopt(c.USERAGENT, 'curl')
    114.     c.setopt(c.VERBOSE, False)
    115.     c.setopt(c.HTTPHEADER, ['Content-Type: application/octet-stream'])
    116.     c.setopt(c.UPLOAD, True)
    117.     c.setopt(c.USE_SSL, True)
    118.     c.setopt(c.READFUNCTION, open('empty.txt', 'rb').read)
    119.     c.setopt(c.PROGRESSFUNCTION, readProgress)
    120.     c.setopt(c.NOPROGRESS, False)
    121.     c.perform()
    122.  
    123.     remove(ulName)
    124.  
    125.     speedCollection = speedCollection[1:]
    126.     speedCollection.reverse()
    127.     speedCollection = speedCollection[1:]
    128.  
    129.     speedMin = speedCollection[0]
    130.     speedMax = speedCollection[0]
    131.     speedTotal = 0
    132.  
    133.     ulSpeed = c.getinfo(c.SPEED_UPLOAD) / 1000.0 / 1000.0
    134.     ulSize = c.getinfo(c.SIZE_UPLOAD)
    135.     ulTime = c.getinfo(c.TOTAL_TIME)
    136.  
    137.     for index, item in enumerate(speedCollection):
    138.         try:
    139.             speed = item - speedCollection[index + 1]
    140.         except:
    141.             break
    142.  
    143.     if speed < speedMin:
    144.         speedMin = speed
    145.     if speed > speedMax:
    146.         speedMax = speed
    147.  
    148.     speedTotal += speed
    149.  
    150.     speedMin = speedMin / 1024.0
    151.     speedMax = speedMax / 1024.0
    152.     speedAverage = speedTotal / len(speedCollection)
    153.  
    154.     print('\n\nFinished uploading \'%s\', %d bytes ( %.3f MB)\n\nAverage speed of %.3f MiB\n[MIN: %.3f KB ::: MAX: %.3f Kb ::: AVG: %.3f KB]\n\nMeasured in %d minutes and %d seconds (%.3f seconds total)\n\n' % (
    155.     ulName, ulSize, ulSize / 1024.0 / 1024.0, ulSpeed, speedMin, speedMax * 2.0, speedAverage, ulTime / 60, ulTime % 60.0, ulTime))
    156.  
    157.     c.close()
    158.  
    159. # ------------------------------------------------------------------------
    160.  
    161. if __name__ == "__main__":
    162.     if len(sys.argv) == 1:
    163.         downloadSpeedTest()
    164.         uploadSpeedtest()
    165.     else:
    166.         for option in sys.argv:
    167.             if option == '-d':
    168.                 downloadSpeedTest()
    169.             elif option == '-u':
    170.                 uploadSpeedtest()
    171.  
    *edit: Download als Anhang - ".txt" einfach entfernen.
    Angehängte Dateien Angehängte Dateien
    Für diesen Beitrag bedankt sich phre4k
    Geändert von theSplit (03.06.19 um 09:46 Uhr) Grund: Attachment + Shebang Zeile
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

  10. #10
    Mitglied

    (Threadstarter)

    Avatar von phre4k
    Registriert seit
    Mar 2015
    Beiträge
    5.463
    ngb:news Artikel
    4

    Re: Unitymedia Speedtest mit Python

    krasser Typ ey danke

    wenn die das jetzt noch in ihrem System sehen… ich ruf mal bei der Hotline an wenn mir langweilig ist
    *mit Linux wäre das natürlich nicht passiert™
    Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say. – Edward Snowden
    tilde.fun – dein kostenloser Linux-Account in der Cloud | Inoffizielle ngb-Telegram-Gruppe
    GCM/S/TW d s+:- a-----? C++$ UL+++$ P-- L+++ E---- W++++ !N ?K w- M-- !P[A-Z] Y++ PGP R* tv-- b++>++++ DI++\:\( G+ e+>++++ h*

  11. #11

    Lightbulb Re: Unitymedia Speedtest mit Python

    @phre4k: Ich habe noch eine Version bei der der Provider/ISP ermittelt und angezeigt werden, einzig allein das "Post" zum Speichern funktioniert nicht, ich weiß nur nicht warum und weshalb. Vermutlich weil die ID dynamisch ermittelt wird, I dont know unfortunately. Aber von der API bekomme ich ein "OK" zurück. Nur wirds irgendwo anders hapern.
    Angehängte Dateien Angehängte Dateien
    Gruß theSplit
    @ I might be sober. The good things... the bad things... all I ever know is here! @
    +++ thunderNote +++ Thom's Inventarverwaltung +++ Pi-Thread +++ IT-Talents Code Competitions +++ NGB-Statistik Opt-Out/Anonymisierung +++ Stonerhead +++ Add-on Flag Cookies +++ Google Image Directlinks +++ dwrox.net

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •