Last active
March 14, 2016 15:05
-
-
Save cab404/f6410df0c5474a622ca3 to your computer and use it in GitHub Desktop.
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 | |
| # Simple network scan based on ICMP echo requests. | |
| # Something for when arp scanning is not working. | |
| # @author cab404 | |
| if [[ -z $2 ]]; then | |
| echo "specify mask and bit length like so: '192.168.1.0 24'" | |
| exit 0; | |
| fi | |
| c1=$(echo $1 | grep -Po '([0-9]{1,3})' | head -n1 | tail -1) | |
| c2=$(echo $1 | grep -Po '([0-9]{1,3})' | head -n2 | tail -1) | |
| c3=$(echo $1 | grep -Po '([0-9]{1,3})' | head -n3 | tail -1) | |
| c4=$(echo $1 | grep -Po '([0-9]{1,3})' | head -n4 | tail -1) | |
| BC=$2 | |
| let ' | |
| bitmask=c1<<24|c2<<16|c3<<8|c4, | |
| host_count=(1<<(32-BC)) | |
| ' | |
| host=0; running=1; | |
| while [[ $running == 1 ]]; do | |
| let ' | |
| ip_bytes=bitmask^host, | |
| c1=(ip_bytes&(255<<24))>>24, | |
| c2=(ip_bytes&(255<<16))>>16, | |
| c3=(ip_bytes&(255<<8))>>8, | |
| c4=(ip_bytes&(255<<0))>>0, | |
| running=++host<host_count | |
| ' | |
| ip=$c1.$c2.$c3.$c4; | |
| echo -ne "$ip: \t"; | |
| ping -c 1 -w 1 $ip | grep "64 bytes" & | |
| pid=$!; sleep 0.01s; disown $pid; kill -9 $pid > /dev/null 2>&1; | |
| echo -ne "\r" | |
| done | |
| echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment