Skip to content

Control the PoE ports of a Zyxel GS1200-5HP switch with a simple Bash script.

License

Notifications You must be signed in to change notification settings

cretl/gs1200hp-ctrl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

gs1200hp-ctrl

TL;DR

Control the PoE ports of a Zyxel GS1200-5HP switch with a simple Bash script.
Only Bash, curl and printf are needed.

Info

With this simple Bash script you can control the PoE ports of a Zyxel GS1200-5HP v2 PoE switch.
The script may also work with hardware revision v1.
Tested firmware: V2.00(ABKN.1)C0 (latest available firmware at 2021/11/01).

Script

Dependencies

Bash, curl and printf. Just install with e.g. apt install bash curl printf

Installation

  1. Just copy the script to a file.
  2. Edit the settings part in the script.
  3. Make the file executeable (e.g., with chmod +x).
  4. Run the script: ./gs1200c.sh {on|off|status} {1|2|3|4|all}

Script actions

The script uses the web interface of the switch to set the currently active PoE ports.
It does perform the following steps:

  1. Login to the switch's web interface with the supplied IP address and password. If the firmware version requires an "encryption" of the password it is done before the login.
  2. The script saves the session cookie, which is required to perform the following steps.
  3. Analyze the currently active ports by getting the http://${switchIP}/port_state_data.js file.
  4. Getting the active PoE ports by posting to the http://$switchIP/port_state_set.cgi file.
  5. After completing the script does log out to be able to login again.

Background

The 4 PoE ports of the switch have the following numerical values:
port1=1; port2=2; port3=4; port4=8
The currently active PoE ports are calculates by combining these values.
Examples: 0=[off]; 1=[1 on]; 3=[1&2 on]; 5=[1&2&3 on]; 15=[1&2&3&4 on];
There are 16 combinations possible.

Important notes

  • After logging in and while a user session is active the switch blocks any other connection attempt to the HTTP port. You must successfully log out to be able to login again. If you fail to successfully logout, you must either restart (powercycle) the switch or wait for the session timeout (about 5 minutes).
  • The script is currently only tested with the firmware version V2.00(ABKN.0)C0. Newer versions may break the functionality.