Skip to content

Instantly share code, notes, and snippets.

@chytreg
Last active August 29, 2015 14:08
Show Gist options
  • Save chytreg/3e8704960acaf4db6108 to your computer and use it in GitHub Desktop.
Save chytreg/3e8704960acaf4db6108 to your computer and use it in GitHub Desktop.
Get random HipChat IP and modify /etc/hosts
#!/usr/bin/env bash
set -e
rand() {
printf $(( $1 * RANDOM / 32767 ))
}
rand_element () {
local -a th=("$@")
unset th[0]
printf $'%s\n' "${th[$(($(rand "${#th[*]}")+1))]}"
}
echo "* Downloading list of HipChat IPs"
ips=($(curl --progress-bar https://www.hipchat.com/help/networking | grep -Eo "(([0-9]{1,3}\.){3}[0-9]{1,3})"))
selected_ip="$(rand_element ${ips[*]}) chat-main.hipchat.com"
echo "* Selected IP: $selected_ip"
echo "* Modify /etc/hosts"
sudo sed -i '' '/chat-main.hipchat/d' /etc/hosts
echo $selected_ip | sudo tee -a /etc/hosts > /dev/null
echo "* Done"
@chytreg
Copy link
Author

chytreg commented Oct 28, 2014

You can use the one-liner below to run it locally:
curl -fsSL http://bitly.com/10wDsM7 | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment