Giter Site home page Giter Site logo

asusrouter's Introduction

GitHub Release License
Downloads Commit activityBuy Me A Coffee

AsusRouter

AsusRouter is an API wrapper for communication with ASUSWRT-powered routers using HTTP(S) protocols. The library supports both the stock AsusWRT firmware and AsusWRT-Merlin.

Up till now, it is only used for the custom AsusRouter Home Assistant integration. But I am always open to making it suitable for any other use.

Installation

Installation of the latest release is available from PyPI:

pip install asusrouter

Usage

Once installed, you can import the AsusRouter class from the module. Example shows the default parameters except for host, username and password.

from asusrouter import AsusRouter

router = AsusRouter(host = "router.my.address",         #required - both IP and URL supported
                    username = "admin",                 #required
                    password = "password",              #required
                    port = None,                        #optional - default port would be selected based on use_ssl parameter
                    use_ssl = False,                    #optional
                    cache_time = 5)                     #optional

Supported devices

AsusRouter supports virtually every AsusWRT-powered device.

WiFi 7 | 802.11be

Model Status Tested firmware Find it on Amazon1
GT-BE98 ๐Ÿ’› Expected to work find it
GT-BE98 Pro ๐Ÿ’› Expected to work find it
RT-BE96U ๐Ÿ’› Expected to work find it
ZenWiFi BQ16 Pro ๐Ÿ’› Expected to work find it

WiFi 6e | 802.11axe

Model Status Tested firmware Find it on Amazon1
GT-AXE11000 ๐Ÿ’› Expected to work find it
GT-AXE16000 ๐Ÿ’š Confirmed Stock:
  • 388.21617
  • find it
    RT-AXE7800 ๐Ÿ’š Confirmed Stock:
  • 388_22068
  • find it
    ZenWiFi ET8 ๐Ÿ’š Confirmed Stock:
  • 388.23759
  • find it
    ZenWiFi Pro ET12 ๐Ÿ’š Confirmed Stock:
  • 388.23013
  • find it

    WiFi 6 | 802.11ax

    Model Status Tested firmware Find it on Amazon1
    DSL-AX82U ๐Ÿ’š Confirmed Merlin:
  • 386.07_0-gnuton0_beta2
  • find it
    GT-AX11000 ๐Ÿ’š Confirmed Merlin:
  • 386.7_2
  • 388.1_0
  • 388.4_0
  • find it
    GT-AX11000 Pro ๐Ÿ’š Confirmed Stock:
  • 388.24198
  • find it
    GT-AX6000 ๐Ÿ’› Expected to work find it
    GT6 ๐Ÿ’› Expected to work find it
    RT-AX52 ๐Ÿ’› Expected to work find it
    RT-AX53U ๐Ÿ’š Confirmed Stock:
  • 386.69061
  • find it
    RT-AX55 ๐Ÿ’š Confirmed Stock:
  • 386.50410
  • 386.52041
  • find it
    RT-AX56U ๐Ÿ’š Confirmed Merlin:
  • 386.7_2
  • 388.1_0
  • 388.2_2
  • find it
    RT-AX57 ๐Ÿ’› Expected to work find it
    RT-AX57 Go ๐Ÿ’› Expected to work find it
    RT-AX58U ๐Ÿ’š Confirmed Stock:
  • 386.49674
  • 388.22237
  • Merlin:
  • 386.7_2
  • 388.1_0
  • 388.4_0
  • find it
    RT-AX59U ๐Ÿ’› Expected to work find it
    RT-AX68U ๐Ÿ’š Confirmed Stock:
  • 388.21732
  • find it
    RT-AX82U ๐Ÿ’š Confirmed Stock:
  • 386.48664
  • 386.49674
  • find it
    RT-AX86S ๐Ÿ’š Confirmed Stock:
  • 386.46061
  • 386.48260
  • 386.49447
  • 388.22525
  • Merlin:
  • 386.7_2
  • find it
    RT-AX86U ๐Ÿ’š Confirmed Stock:
  • 386.46061
  • 386.48260
  • 386.49447
  • 388.22525
  • Merlin:
  • 386.7_2
  • 388.4_0
  • find it
    RT-AX86U Pro ๐Ÿ’š Confirmed Stock:
  • 388.23565
  • find it
    RT-AX88U ๐Ÿ’š Confirmed Stock:
  • 386.45934
  • 386.48631
  • 388.24198
  • Merlin:
  • 386.5_2
  • 386.8_0
  • 388.1_0
  • 388.2_0
  • 388.4_0
  • find it
    RT-AX88U Pro ๐Ÿ’š Confirmed Merlin:
  • 388.4_0
  • find it
    RT-AX89X ๐Ÿ’š Confirmed find it
    RT-AX92U ๐Ÿ’š Confirmed Stock:
  • 386.46061
  • find it
    TUF-AX3000 V2 ๐Ÿ’š Confirmed Stock:
  • 388.23785
  • find it
    TUF-AX4200 ๐Ÿ’› Expected to work find it
    TUF-AX5400 ๐Ÿ’š Confirmed Stock:
  • 386.50224
  • 388.21224
  • 388.22525
  • 388.23285
  • Merlin:
  • 388.4_0
  • find it
    TUF-AX6000 ๐Ÿ’š Confirmed Stock:
  • 388.32432
  • find it
    ZenWiFi AX (XT8) ๐Ÿ’š Confirmed Stock:
  • 386.48706
  • 388.23285
  • Merlin:
  • 386.7_2-gnuton1
  • find it
    ZenWiFi AX Hybrid (XP4) ๐Ÿ’› Expected to work find it
    ZenWiFi AX Mini (XD4) ๐Ÿ’š Confirmed Stock:
  • 386.48790
  • 386.49599
  • find it
    ZenWiFi Pro XT12 ๐Ÿ’š Confirmed Stock:
  • 388.22127
  • find it
    ZenWiFi XD4 Plus ๐Ÿ’› Expected to work find it
    ZenWiFi XD4S ๐Ÿ’› Expected to work find it
    ZenWiFi XD5 ๐Ÿ’› Expected to work find it
    ZenWiFi XD6 ๐Ÿ’š Confirmed Stock:
  • 388.21380
  • find it
    ZenWiFi XD6S ๐Ÿ’š Confirmed Stock:
  • 388.21380
  • find it
    ZenWiFi XT9 ๐Ÿ’š Confirmed Stock:
  • 388_23285
  • find it

    WiFi 5 | 802.11ac

    Model Status Tested firmware Find it on Amazon1
    4G-AC55U ๐Ÿ’š Confirmed Stock:
  • 380.8102
  • find it
    DSL-AC68U ๐Ÿ’š Confirmed Stock:
  • 386.47534
  • 386.50117
  • Merlin:
  • 386.4-gnuton2
  • 386.7_2-gnuton1
  • find it
    RT-AC51U ๐Ÿ’š Confirmed Stock:
  • 380.8591
  • find it
    RT-AC52U B1 ๐Ÿ’š Confirmed find it
    RT-AC5300 ๐Ÿ’š Confirmed Merlin:
  • 386.7_2
  • find it
    RT-AC57U V3 ๐Ÿ’š Confirmed Stock:
  • 386.21649
  • find it
    RT-AC58U ๐Ÿ’š Confirmed find it
    RT-AC66U ๐Ÿ’š Confirmed Merlin:
  • 380.70_0
  • find it
    RT-AC66U B1 ๐Ÿ’š Confirmed Stock:
  • 386.51255
  • find it
    RT-AC68U ๐Ÿ’š Confirmed Stock:
  • 386.49703
  • Merlin:
  • 386.5_2
  • 386.7_0
  • find it
    RT-AC85P ๐Ÿ’š Confirmed Stock:
  • 382.52516
  • find it
    RT-AC86U ๐Ÿ’š Confirmed Stock:
  • 386.48260
  • 386.49709
  • Merlin:
  • 386.7_0
  • 386.7_2
  • 386.9_0
  • find it
    RT-AC87U ๐Ÿ’š Confirmed Merlin:
  • 384.13_10
  • find it
    RT-AC88U ๐Ÿ’š Confirmed Stock:
  • 386.48260
  • Merlin:
  • 386.5_0
  • 386.7_beta1
  • 386.12_2
  • find it
    RT-ACRH17 ๐Ÿ’š Confirmed Stock:
  • 382.52517
  • find it
    ZenWiFi AC Mini(CD6) ๐Ÿ’› Expected to work find it

    WiFi 4 | 802.11n

    Model Status Tested firmware Find it on Amazon1
    RT-N66U ๐Ÿ’š Confirmed find it

    Support the library

    Issues and Pull requests

    If you have found an issue working with the library or just want to ask for a new feature, please fill in a new issue.

    You are also welcome to submit pull requests to the repository!

    Check it with your device

    Testing the library with different devices would help a lot in the development process. Unfortunately, currently, I have only one device available, so your help would be much appreciated.

    Other support

    This library is a free-time project. If you like it, you can support me by buying a coffee.

    Buy Me A Coffee

    Footnotes

    1. As an Amazon Associate I earn from qualifying purchases. Not like I ever got anything yet (: โ†ฉ โ†ฉ2 โ†ฉ3 โ†ฉ4 โ†ฉ5

    asusrouter's People

    Contributors

    dependabot[bot] avatar imarkus avatar vaskivskyi avatar

    Stargazers

     avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

    Watchers

     avatar

    asusrouter's Issues

    AsusData.CLIENTS is not serialiazble when trying to convert to JSON

    Hello @Vaskivskyi,
    I really like your library, as I want to do some automation with it (specifically switching back 5GHz Channels to DSF >100 if Radar-Detection swaps it with something like 36 / 40 and the like).

    However I think I bumped into an error
    data= loop.run_until_complete(router.async_get_data(AsusData.CLIENTS)
    if I do the following

    json.dumps(data)
    
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.11/json/__init__.py", line 231, in dumps
        return _default_encoder.encode(obj)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/json/encoder.py", line 200, in encode
        chunks = self.iterencode(o, _one_shot=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/json/encoder.py", line 258, in iterencode
        return _iterencode(o, 0)
               ^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/json/encoder.py", line 180, in default
        raise TypeError(f'Object of type {o.__class__.__name__} '
    TypeError: Object of type AsusClient is not JSON serializable
    

    Any clues? Did I miss something?
    Thank you,
    Joachim

    [DEVICES] New devices have different WAN traffic limit

    Newer devices (e.g. RT-AX88U) have a different limit on traffic count than 4 GB, as it was before (e.g. RT-AC66U)

    Either a list of known devices should be implemented, or this data should be fetched from the device automatically

    If not implemented, this will result in large spikes in the calculated speeds when the value overflows

    Traffic analyzer info

    Hi,

    Is there a way to use this to fetch usage information? This is the type of things in the "Traffic Analyzer" section of the webui:

    image

    Right now I'm doing some sketchy logic where I ssh to the router, fetch the /jffs/.sys/TrafficAnalyzer/TrafficAnalyzer.db file then locally fudge with it. Though was wondering if a more legit API exists.

    Thanks!

    "Enable block all devices" toggle

    Hi,

    Thank you for this wonderful library. I tried running the example script and enabling/disabling parental controls, and everything worked like a charm with my Asus-Merlin AXE-16000.

    I am trying to toggle internet access to the whole network and there is a setting for it in parental controls, called 'Enable block all devices", however, I do not see any way of toggling it through this project. Is there a way this functionality can be supported?

    image

    aiohttp.ClientSession is unclosed after disconnect calls

    Hello!

    I noticed when running examples from the documentation, that after calling router.async_disconnect(), there is a message printed to stdout:

    async def gather_data(host, username, password, use_ssl):
        """Method to gether the known data"""
        # async with aiohttp.ClientSession() as session:
            # Initialize
        router = AsusRouter(
            hostname=host, username=username, password=password,
            use_ssl=use_ssl,
        )
    
        # Connect
        await router.async_connect()
    
        # Get the client list
        clients = await router.async_get_data(AsusData.CLIENTS)
        for client in clients.items():
            print(client)
    
        # Disconnect
        await router.async_disconnect()
    
    
    
    if __name__ == '__main__':
        _host = "asusrouter.com"
        _username = "USERNAME"
        _passwsord = "PASSWORD"
        _use_ssl = False
        loop = asyncio.new_event_loop()
        loop.run_until_complete(gather_data(_host, _username, _password, _use_ssl))
    
    
    >> Unclosed client session
    >> client_session: <aiohttp.client.ClientSession object at 0x10ae37990>

    Digging into it, it does not look like aiohttp.client.ClientSessions created by asusrouter.connection.Connectionfunctions are ever expressly closed.

    This could be fine if the API required the user to explicitly create a new Session themselves in a context manager and pass that reference to the AsusRouter constructor, but the signature for AsusRouter shows session as being Optional with a default of None.

    This also crops up if a user defined ClientSession is passed and then closed before another API call is made. For example, in Connection._make_post_request a new ClientSession is created if none exists or is closed,

            # Check if a session is available
            if self._session is None or self._session.closed:
                # If no session is available, we cannot be connected to the device
                _LOGGER.debug("No session available. Creating a new one")
                # We will create a new session and retry the request
                self.reset_connection()
                self._session = self._new_session()
                # Reconnect
                await self.async_connect()
                # Retry the request
                return await self._make_post_request(endpoint, payload, headers)

    but this Session is outside of a user's control to close themselves and Connection does not close that session.

    I might have missed some function that makes this a non-issue, in which case I would just ask that the documentation reflect this as an example :)

    How do you use this?

    How to use this? there are no examples or README has very limited information

    Get CPU temperature working in Netgear R6300V2 running Merlin 380.70

    CPU temperature is not working on Netgear R6300V2 router running Merlin 380.70

    "cpu": ['curr_cpuTemp="([0-9.]+)"'],

    ^Above does not match what I have from my router's /ajax_coretmp.asp:

    curr_coreTmp_2_raw = "44&deg;C";
    curr_coreTmp_2 = (curr_coreTmp_2_raw.indexOf("disabled") > 0 ? 0 : curr_coreTmp_2_raw.replace("&deg;C", ""));
    curr_coreTmp_5_raw = "47&deg;C";
    curr_coreTmp_5 = (curr_coreTmp_5_raw.indexOf("disabled") > 0 ? 0 : curr_coreTmp_5_raw.replace("&deg;C", ""));
    curr_coreTmp_cpu = "58";
    

    It's actually curr_coreTmp_cpu rather than curr_cpuTemp

    I have not checked whether this applies to: (a) stock Asus, or (b) Merlin specific or (c) customization specifically made for Netgear devices. Although (c) seems highly unlikely.

    Thanks for your awesome ha integration anyway!

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.