{"id":462,"date":"2024-03-01T13:43:15","date_gmt":"2024-03-01T03:43:15","guid":{"rendered":"http:\/\/www.mrmarkyoung.com\/oracle\/?p=462"},"modified":"2024-03-01T13:43:17","modified_gmt":"2024-03-01T03:43:17","slug":"asus-router-firmware-upgrade-notification","status":"publish","type":"post","link":"http:\/\/www.mrmarkyoung.com\/oracle\/2024\/03\/01\/asus-router-firmware-upgrade-notification\/","title":{"rendered":"ASUS Router Firmware Upgrade Notification"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have written this pice of code to let me know when there is a new firmware upgrade of my router. This should work on most of the ASUS Routers. I&#8217;ve tested only on RT-AX86U. I&#8217;ve scheduled this from my PC to run once a day.<br><br>I&#8217;m using Pushover to get the notifications on my Iphone, but you could use any method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import paramiko\nimport http.client\nimport urllib\n\n# RT-AX86U\ndef sendnotification(MyTitle):\n    conn = http.client.HTTPSConnection(\"api.pushover.net:443\")\n    conn.request(\n        \"POST\",\n        \"\/1\/messages.json\",\n        urllib.parse.urlencode(\n            {\n                \"token\": \"&lt;put your token here>\",\n                \"user\": \"&lt;your username here>\",\n                \"message\": \"Firmware Update \" + MyTitle,\n            }\n        ),\n        {\"Content-type\": \"application\/x-www-form-urlencoded\"},\n    )\n    conn.getresponse()\n\n\ndef ssh_get_fw(version_type):\n\n    # SSH connection parameters\n    hostname = \"&lt;HOST IP>\"\n    port = 22\n    username = \"&lt;USERNAME>\"\n    password = \"&lt;PASSWORD>\"\n\n    # Create an SSH client\n    client = paramiko.SSHClient()\n    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n\n    try:\n        # Connect to the router\n        client.connect(\n            hostname, port=port, username=username, password=password, timeout=10\n        )\n\n        # Execute the command\n        stdin, stdout, stderr = client.exec_command(version_type)\n\n        # Read the output\n        firmware_version = stdout.read().decode().strip().replace(\"_\", \"\")\n\n    except paramiko.AuthenticationException:\n        print(\"Authentication failed. Please check your username and password.\")\n    except paramiko.SSHException as e:\n        print(\"SSH connection failed:\", str(e))\n    finally:\n        # Close the SSH connection\n        client.close()\n    return firmware_version\n\n\n# The webs_state_info will change once the router goes off and does it check\nmerlin_version = ssh_get_fw(\"nvram get webs_state_info\")&#91;4:]\nbuild_version = ssh_get_fw(\"nvram get buildno\").replace(\".\", \"\")\nextend_no = ssh_get_fw(\" nvram get extendno\")\n\nresult = int(str(build_version) + str(extend_no))\nprint(f\"Merlins Web version is {merlin_version}\")\n\nprint(f\"current firmware version is {result}\")\nif int(merlin_version) > result:\n    print(\"please update the firmware\")\n    sendnotification(result)\nelse:\n    print(\"Nothing to update\")\n    sendnotification(\"Nothing to update\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have written this pice of code to let me know when there is a new firmware upgrade of my router. This should work on most of the ASUS Routers. I&#8217;ve tested only on RT-AX86U. I&#8217;ve scheduled this from my PC to run once a day. I&#8217;m using Pushover to get the notifications on my &#8230; <a title=\"ASUS Router Firmware Upgrade Notification\" class=\"read-more\" href=\"http:\/\/www.mrmarkyoung.com\/oracle\/2024\/03\/01\/asus-router-firmware-upgrade-notification\/\" aria-label=\"Read more about ASUS Router Firmware Upgrade Notification\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":1,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":463,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/462\/revisions\/463"}],"wp:attachment":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}