Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active September 22, 2016 07:58
Show Gist options
  • Select an option

  • Save Alex1990/c7c95a61198dfd36efe67c63227577d1 to your computer and use it in GitHub Desktop.

Select an option

Save Alex1990/c7c95a61198dfd36efe67c63227577d1 to your computer and use it in GitHub Desktop.
Find available ports in bash
#!/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