Created
April 9, 2014 11:43
-
-
Save 0robustus1/10259075 to your computer and use it in GitHub Desktop.
Finding development rails servers inside a given subnet
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
| #!/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