Control the PoE ports of a Zyxel GS1200-5HP switch with a simple Bash script.
Only Bash, curl and printf are needed.
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).
Bash, curl and printf.
Just install with e.g. apt install bash curl printf
- Just copy the script to a file.
- Edit the settings part in the script.
- Make the file executeable (e.g., with chmod +x).
- Run the script:
./gs1200c.sh {on|off|status} {1|2|3|4|all}
The script uses the web interface of the switch to set the currently active PoE ports.
It does perform the following steps:
- 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.
- The script saves the session cookie, which is required to perform the following steps.
- Analyze the currently active ports by getting the http://${switchIP}/port_state_data.js file.
- Getting the active PoE ports by posting to the http://$switchIP/port_state_set.cgi file.
- After completing the script does log out to be able to login again.
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.
- 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.