whoIsOnMySubnet 473 B

1234567891011121314151617181920212223
  1. #! /bin/bash
  2. #
  3. # A quick script to see who (DNS names) are on the same subnet.
  4. # Assumes eth0 and /24.
  5. #
  6. # Usage: onMySubnet [ip]
  7. #
  8. # George Jones <gmj@pobox.com>, Wed Sep 30 05:50:02 2015
  9. #
  10. eth0Addr=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
  11. addrWith4Octets="${1:-${eth0Addr}}"
  12. addrWith3Octets=`echo $addrWith4Octets | cut -d"." -f1-3`
  13. i=1;
  14. while [ "$i" -lt 255 ]; do
  15. host ${addrWith3Octets}.$i | grep -v NX;
  16. i=$((i+1));
  17. done