Skip to content

Instantly share code, notes, and snippets.

@0robustus1
Created April 9, 2014 11:43
Show Gist options
  • Select an option

  • Save 0robustus1/10259075 to your computer and use it in GitHub Desktop.

Select an option

Save 0robustus1/10259075 to your computer and use it in GitHub Desktop.
Finding development rails servers inside a given subnet
#!/bin/bash
# The nmap compatible address-range is taken as first (and only) commandline
# argument. The output contains the whole url (including `http://` and the
# port, so it could be used by xdg-open or open. (As long as you're using it
# in a for loop)
port=3000
address_range=$1
all_active_hosts_in_net=$(nmap -sn $address_range)
active_ip_addresses=$(echo $all_active_hosts_in_net | grep -oP "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
for ip_address in $active_ip_addresses; do
url="http://$ip_address:$port"
response=$(curl -s -m 1 --head --request GET $url)
if [[ -n $response ]]; then
echo $url
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment