Skip to content

Instantly share code, notes, and snippets.

@harunyardimci
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save harunyardimci/8955138 to your computer and use it in GitHub Desktop.

Select an option

Save harunyardimci/8955138 to your computer and use it in GitHub Desktop.
find connected hostnames from netstat output
netstat -tuna | awk '$5 ~ /^[0-9]/ { print $5 }' | sed -e '/:[0-9]*/s/:[0-9]*//' | sort | uniq -c | sort -rn | while read line; do COUNT=$(echo $line | awk '{ print $1 }'); IP=$(echo $line | awk '{ print $2 }'); HNAME=$(dig +short -x ${IP}); if [ -z "$HNAME" ]; then HNAME=${IP}; fi; echo ${COUNT} ${HNAME}; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment