Last active
September 9, 2016 05:16
-
-
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
This file contains 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 | |
# | |
# A simple bash script to look up | |
# who owns an IP Address based on | |
# the IP address's whois data | |
# | |
# Author: Liam Haworth <[email protected]> | |
# | |
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