Skip to content

Instantly share code, notes, and snippets.

@KatelynHaworth
Last active September 9, 2016 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatelynHaworth/022bd0a1b4c1183479f88fba9989adaf to your computer and use it in GitHub Desktop.
Save KatelynHaworth/022bd0a1b4c1183479f88fba9989adaf to your computer and use it in GitHub Desktop.
A simple bash tool to lookup the own of an IP address. TL;DR a straight to the point whois
#!/bin/bash
#
# A simple bash script to look up
# who owns an IP Address based on
# the IP address's whois data
#
# Author: Liam Haworth <liam@haworth.id.au>
#
IPADDR=$1
WHOIS_DATA=$(whois $IPADDR)
FIELDS=("org-name" "OrgName" "descr" "owner")
for field in ${FIELDS[@]}; do
OWNER=$(echo "$WHOIS_DATA" | awk -v whoisField="$field:" '$0 ~ whoisField {$1 = ""; sub(/^[ \t\r\n]+/, "", $0); print $0}')
if [ ! -z "${OWNER}" ]; then
break
fi
done
if [ -z "${OWNER}" ]; then
OWNER="UNKOWN (Not in database)"
fi
echo -e "\033[32mIP Address [\033[31m$IPADDR\033[32m] belongs to [\033[33m$OWNER\033[32m]\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment