On box python huawei

Python HTTP API client for Huawei Modems

This is a python library to interact with a Huawei modem over HTTP API.

The library has been tested on these devices:

  • E5180
  • E8372
  • B315
  • B529s-23a
  • H122-373 (HUAWEI 5G CPE Pro 2 locoked to the UK Network Three)

Please let me know if you tested it successfully with other modems as well.

Currently Supported

  • webserver
    • get_session_token_info: gets a session token to use
    • login: creates a new session on the HTTP API
    • logout: deletes current session on the HTTP API
    • get_sms: get information from boxes: inbox, outbox
    • send_sms: sends an SMS through device’s modem
    • delete_sms: deletes an sms from one of their boxes
    • sms_count: get the sms count on each box
    • sms_set_read: set the sms status to read
    • status: get status of ussd. This will tell you if there are ussd messages available to read
    • send: sends a ussd message
    • get: retrieves a ussd message
    • get_connected_hosts: gets a list of connected devices
    • block_host: blocks the device from network
    • unblock_host: unblock device on network
    • get_blocked_hosts: gets a list of blocked devices
    • is_host_blocked: checks if device is blocked
    • switch_wlan_24ghz: allows to switch on or off the wlan 2.4Ghz module of the router
    • switch_wlan_5ghz: allows to switch on or off the wlan 5Ghz module of the router
    • connect_mobile: enables mobile (ie LTE / 4G / 3G / etc) network
    • disconnect_mobile: disables mobile network
    • get_mobile_status: checks the mobile connection status
    • reboot: reboots the modem

    Prerequisites

    requests library (and its dependencies) is required. six library (and its dependencies for Python 2 and 3 compatibility) typing library (support for type hints)

    This is requirements.txt content:

    requests>=2.25.1 six>=1.15.0 typing>=3.7.4.3 

    Installing

    pip install huawei-modem-api-client

    Example

       Note: The default modem host is assumed to be 192.168.8.1 . If that is not the case for you, you can specify your modem ip as follows:

    HTTPS Examples

    When the router uses HTTPS instead of HTTP, you can pass the uri_scheme when creating the context instance which becomes used on subsequent api calls that use the same context.

    If the router that uses HTTPS uses self-signed certificates, there will be SSL errors. You can ignore certificate validation/verification as follows:

    Contributing

    Send me a PM if you want to contribute.

    Authors

    License

    This project is licensed under the MIT License — see the LICENSE.md file for details

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    Modem USB Huawei HTTP API Python client

    License

    pablo/huawei-modem-python-api-client

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    Python HTTP API client for Huawei Modems

    This is a python library to interact with a Huawei modem over HTTP API.

    The library has been tested on these devices:

    • E5180
    • E8372
    • B315
    • B529s-23a
    • H122-373 (HUAWEI 5G CPE Pro 2 locoked to the UK Network Three)

    Please let me know if you tested it successfully with other modems as well.

    • webserver
      • get_session_token_info: gets a session token to use
      • login: creates a new session on the HTTP API
      • logout: deletes current session on the HTTP API
      • get_sms: get information from boxes: inbox, outbox
      • send_sms: sends an SMS through device’s modem
      • delete_sms: deletes an sms from one of their boxes
      • sms_count: get the sms count on each box
      • sms_set_read: set the sms status to read
      • status: get status of ussd. This will tell you if there are ussd messages available to read
      • send: sends a ussd message
      • get: retrieves a ussd message
      • get_connected_hosts: gets a list of connected devices
      • block_host: blocks the device from network
      • unblock_host: unblock device on network
      • get_blocked_hosts: gets a list of blocked devices
      • is_host_blocked: checks if device is blocked
      • switch_wlan_24ghz: allows to switch on or off the wlan 2.4Ghz module of the router
      • switch_wlan_5ghz: allows to switch on or off the wlan 5Ghz module of the router
      • connect_mobile: enables mobile (ie LTE / 4G / 3G / etc) network
      • disconnect_mobile: disables mobile network
      • get_mobile_status: checks the mobile connection status
      • reboot: reboots the modem

      requests library (and its dependencies) is required. six library (and its dependencies for Python 2 and 3 compatibility) typing library (support for type hints)

      This is requirements.txt content:

      requests>=2.25.1 six>=1.15.0 typing>=3.7.4.3 
      pip install huawei-modem-api-client
      import huaweisms.api.user import huaweisms.api.wlan import huaweisms.api.sms ctx = huaweisms.api.user.quick_login("myusername", "mypassword") print(ctx) # output: # sending sms huaweisms.api.sms.send_sms( ctx, 'phone-number', 'this is the sms message' ) # connected devices device_list = huaweisms.api.wlan.get_connected_hosts(ctx)

      Note: The default modem host is assumed to be 192.168.8.1 . If that is not the case for you, you can specify your modem ip as follows:

      import huaweisms.api.user ctx = huaweisms.api.user.quick_login("myusername", "mypassword", modem_host='10.11.12.13') print(ctx) #output:

      When the router uses HTTPS instead of HTTP, you can pass the uri_scheme when creating the context instance which becomes used on subsequent api calls that use the same context.

      import huaweisms.api.user ctx = huaweisms.api.user.quick_login( 'username', 'password', modem_host='192.168.12.13', uri_scheme='https' )

      If the router that uses HTTPS uses self-signed certificates, there will be SSL errors. You can ignore certificate validation/verification as follows:

      import huaweisms.api.user ctx = huaweisms.api.user.quick_login( 'username', 'password', modem_host='192.168.12.13', uri_scheme='https', verify=False )

      Send me a PM if you want to contribute.

      This project is licensed under the MIT License — see the LICENSE.md file for details

      About

      Modem USB Huawei HTTP API Python client

      Источник

      1. Overview

      The configuration file of the network devices needs to be backed up in a timely manner to ensure device security, reliability, and availability of services. In case of a fault occurs on a device, the backup configuration file can be restore to the device to quickly for the continuity of service. The configuration backup must be operated with secure protocol such as SFTP or SSH only.

      In this article we will do the configuration backup for a list of Huawei router/switch devices with Python script using SSH secure protocol on Linux server running CentOS7.

      2. Prerequisites

      In this tutorial, it is supposed that:

      a. You have already install RHEL/CentOS 7 Linux server up and running. In case that you don’t, you would probably like to read this link. Minimal RHEL/CentOS 7 Installation With Logical Volume Manager (LVM).
      b. You have already done the initial server setup. Please refer to this link Minimal RHEL/CentOS 7 Initial Server Setup.

      c. You already done SSH configuration on Huawei router and switch, Please refer to this link

      3. Scenario Diagram

      There is a Linux server running CentOS7 and connected to Huawei router and switch. From Linux server we can remote SSH to both Huawei router and switch. You can download Python Backup script here Script_BackupConfig_HuaweiRouterSwitch extract it and upload to CentOS7 Linux server.

      Automate Backup Cisco Router/Switch Configuration With Python Script

      There are 2 files. One is the script file and another one is list of host to be backup by this script.You can create a directory any where and keep these 2 files together in the same directory. For our case now, let make directory /var/scripts/netbackup and keep this 2 files there.

      # mkdir -p /var/scripts/netbackup # mv backup_huawei_routerswitch.py /var/scripts/netbackup # mv huawei_routerswitch /var/scripts/netbackup

      In this script will backup router and switch configuration to directory /var/netbackup, so need to create this directory accordingly.

      You need to update USER, PASSWORD, and secret to your own username, password, and enable password.

      # cd /var/scripts/netbackup # vim backup_huawei_routerswitch.py ###authentication USER = 'netadmin' PASSWORD = 'Pa$word2019'

      The script will do multiple devices backup from list of host in file huawei_routerswitch. So, we need to add Cisco router and switch hostname or IP address of remote SSH management into this file. Let use /etc/hosts to have a friendly name of backup file.

      # vim /etc/hosts 192.168.1.14 huawei_router01 192.168.1.15 huawei_switch01 # cd /var/scripts/netbackup # vim cisco_routerswitch huawei_router01 huawei_switch01

      4. Install Prerequesed Phyton Packets

      By default after installing CentOS7 Linux OS, Python version 2.7.5 should be installed there. We can verify with the following command.

      # python --version Python 2.7.5

      To execute this Python script, we need to install the following Python module.

      # yum install python-pip # pip install paramiko

      Now, we should be able to run this Python backup script, but need to make this script executable with the following command.

      # chmod +x backup_huawei_routerswitch.py

      Let test run the script manually with the following commands.

      # ./backup_huawei_routerswitch.py

      Then we need to verify to make sure that the script can backup the Cisco router and switch configuration successfully.

      # ll /var/netbackup total 8 -rw-r--r--. 1 root root 6465 Apr 9 21:24 huawei_router01_2019049_212353 -rw-r--r--. 1 root root 6425 Apr 9 21:24 huawei_switch01_2019049_212354 # du -sh * 11.0K huawei_router01_2019049_212353 9.0K huawei_switch01_2019049_212354 # vim /var/netbackup/dc/huawei_router01_2019049_212353 # vim /var/netbackup/dc/huawei_switch01_2019049_212354

      6. Schedully Run The Script

      Finally, It is time make a cronjob to run this script schedully. Let cronjon run this script everday at 21:00.

      # cd /etc/cron.d # vim netbackup 0 21 * * * root cd /var/scripts/netbackup; /var/scripts/netbackup/backup_huawei_routerswitch.py

      7. Conclusion

      That’s all about doing the configuration backup for a list of Huawei router/switch devices with Python script using SSH secure protocol on Linux server running CentOS7 from Tech Space KH. Hopefully, you can find this guide informative. If you have any questions or suggestions you can always leave your comments below. I will try all of my best to review and reply them.

      Источник

      Читайте также:  Python fast api как запустить
Оцените статью