Coder Social home page Coder Social logo

jonbulica99 / zyxel-poe-manager Goto Github PK

View Code? Open in Web Editor NEW
19.0 8.0 3.0 20 KB

A convenience script to manage the state of the PoE ports of a Zyxel GS1900 series switch.

License: GNU General Public License v2.0

Python 100.00%
networking switch zyxel poe

zyxel-poe-manager's Introduction

zyxel-poe-manager

A convenience script to manage the state of the PoE ports of a Zyxel GS1900 series switch.

Motivation

This was written because my Zyxel GS1900-10HP switch managed to get me angry enough with the abhorrent web interface and inability to do anything useful via SNMP or the CLI. The only thing it does is log into the web management and do the same you would do by clicking approx. 10 times.

Dependencies

This program was written for python3. You are welcome to rewrite it for python2 and make a PR.

The only requirements are requests and BeautifulSoup4 (for HTML parsing). You can install them using pip:

python3 -m pip install -r requirements.txt

This script is compatible with the latest firmware version V2.70(AAZI.1)_20220111 of my GS1900-10HP model rev A1. There are absolutely no guarantees that it will work with your system.

There is a separate release of this script for each firmware! For the previous versions V2.40(AAZI.1)_20180705 and V2.60(AAZI.2)_20200922 please use the older release accordingly.

Usage

usage: poe-manager.py [-h] --host HOST --user USER --password PWD --port PORT
                      [--state {0,1}] [--verbose]

Manage PoE ports for a Zyxel GS1900-10HP switch.

optional arguments:
  -h, --help            show this help message and exit
  --host HOST, -H HOST  The hostname of the switch.
  --user USER, -U USER  An administrative user.
  --password PWD, -P PWD
                        Password of the admin user.
  --port PORT, -p PORT  The port number. When querying information, 0 means
                        all ports.
  --state {0,1}, -s {0,1}
                        Turn the port on (1) or off (0). To query the state,
                        rather than set it, omit this parameter.
  --verbose, -V         Return detailed information when querying the
                        specified port state.

Examples

Turn on PoE port 3

python3 poe-manager.py --host '10.10.10.2' --user admin --password hunter2 --port 3 --state 1

Turn off PoE port 3

python3 poe-manager.py --host '10.10.10.2' --user admin --password hunter2 --port 3 --state 0

Get the current state of PoE port 4

python3 poe-manager.py --host '10.10.10.2' --user admin --password hunter2 --port 4
# Output: Enable

Alternatively, use the --verbose flag to get even more information for port 4:

python3 poe-manager.py --host '10.10.10.2' --user admin --password hunter2 --port 4 --verbose
# Output: {'Port': '4', 'State': 'Enable', 'Class': 'class4', 'PD Priority': 'High', 'Power-Up': '802.3at', 'Wide Range Detection': 'Disable', 'Consuming Power (mW)': '3300', 'Max Power (mW)': '31200'}

Get detailed information for all PoE ports

python3 poe-manager.py --host '10.10.10.2' --user admin --password hunter2 --port 0 --verbose

Bash convenience function

This is how I primarily use this script. Insert the following in your .bashrc:

function poemanager() { /path/to/poe-manager.py -H '10.10.10.2' -U admin -P hunter2 -p $1 -s $2; }

This would make the above examples look like the following:

poemanager 3 1   # turn on port 3
poemanager 3 0   # turn off port 3

Yes, you are saving the password in your .bashrc, but if someone can read arbitrary files in your system you're in much more trouble.

Contribution

If you manage to extend the feature set of this script, I'd really appreciate a PR.

Licensing

This program is licensed under the GPL 2.0 license. For more information, please refer to LICENSE.

zyxel-poe-manager's People

Contributors

jonbulica99 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zyxel-poe-manager's Issues

PD Priority

Just tested sucessfully on a "GS1900-24HP"
Only thing that is anoying is that every change of state will also set 'PD Priority': 'Medium'.

(maybee I can fix on my own, but just lerning python ;)

disable/enable the lan port instead of poe?

Hi.

Is it possible to simply disable/enable the lan port instead of poe? It would be great if you could give me a tip on how to adapt your script for this. I want to use it on an GS1900-24E.

auth failure with firmware V2.70(AAZI.1)C0

hi

just for your info: i just upgraded my switch to the latest firmware (GS1900-10HP_V2.70(AAZI.1)C0) and with this firmware, the auth process from your script seems to be broken:

Traceback (most recent call last):
File "/config/python_scripts/poe-manager.py", line 145, in
main(parser.parse_args())
File "/config/python_scripts/poe-manager.py", line 35, in main
raise Exception("Login failed: %s" % ret2.text)
Exception: Login failed:
Not Auth

according zyxel's changelog for the v2.70 release there were some changes within the auth process. for the moment i switched back to v2.60 and it works again as expected.

Zyxel GS1920-48HP

Hello, I tried this script on Zyxel GS1920-48HP and it is not working for me. Any chance to change the script so it would work also with 1920? It would help me a lot. Thanks.

Traceback (most recent call last):
  File "poe-manager.py", line 144, in <module>
    main(parser.parse_args())
  File "poe-manager.py", line 34, in main
    raise Exception("Login failed: %s" % ret2.text)
Exception: Login failed: <html>
<head>
<title>Object Not Found</title>
</head>
<body>
<h1>Object Not Found</h1>
The requested URL '/cgi-bin/dispatcher.cgi?login_chk=1&dummy=1653921839518' was not found on the RomPager server.<p>
Return to <A HREF="">last page</A><p>

</body>
</html>

extend it to report the PoE status of a port?

Hi,

thanks a lot for this script.
Enables me to integrate it into my fhem based automation.

Do you see a chance to extend it to report the PoE status of a port?

Cheers!

-gramels

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.