Last active
September 22, 2016 07:58
-
-
Save Alex1990/c7c95a61198dfd36efe67c63227577d1 to your computer and use it in GitHub Desktop.
Find available ports in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Get available ports to be used by webpack-dev-server and mock server. | |
| IP=127.0.0.1 | |
| start_port=8000 | |
| end_port=8100 | |
| scanner() { | |
| local port="$start_port" | |
| local avail_ports=$(while [[ ! "$port" -gt "$end_port" ]]; do | |
| lsof -i ":$port" > /dev/null 2>&1 || echo "$port" | |
| ((port++)) | |
| done) | |
| echo "$avail_ports" | |
| return $? | |
| } | |
| scanner | |
| exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment