Sadly, the whois
output seems to be meant for humans, not machines, to read. Its format depends on which root domain you are interested in. For example, whois uio.no
returns stuff like
NORID Handle...............: UIO2O-NORID
Type.......................: organization
Name.......................: UNIVERSITETET I OSLO
Id Type....................: organization_number
Id Number..................: 971035854
Registrar Handle...........: REG2-NORID
Post Address...............: Postboks 1059, Blindern
while whois tasvideos.org
produces
Registrant ID:ACTR120531657
Registrant Name:Andres Delikat
Registrant Organization:tasvideos.org
Registrant Street1:5505G Creek Ridge Ln
Registrant Street2:
Registrant Street3:
Registrant City:Raleigh
This is just to show that parsing this stuff will depend on what you're looking at, and the solution I provide will not work in all cases. But the easiest way to extract this information is by calling awk
and keeping its output. For the ".org" case, which is the one you probably want, it would be something like this:
info=$(whois $ip)
org=$(echo "$info" | awk -F : '$1=="Registrant Organization"{print $2}')
city=$(echo "$info" | awk -F : '$1=="Registrant City"{print $2}')