syf101
syf101

Reputation: 71

How to use command line to get whois information?

I have a large text file on my server that has a list of domains in it that I need to get the contact information for. Here's an example of that's showing up for me when I run whois on stackoverflow.com:

root@server [~]# whois stackoverflow.com
[Querying whois.verisign-grs.com]
[Redirected to whois.name.com]
[Querying whois.name.com]
[whois.name.com]

__   _                             ____
| \ | | __ _ _ __ ___   ___       / ___|___  _ __ ___
|  \| |/ _` | '_ ` _ \ / _ \     | |   / _ \| '_ ` _ \
| |\  | (_| | | | | | |  __/  _  | |__| (_) | | | | | |
|_| \_|\__,_|_| |_| |_|\___| (_)  \____\___/|_| |_| |_|
      On a first name basis with the rest of the world.


Get your <a href="http://www.name.com">domains</a> at Name.com.


Domain Name:     stackoverflow.com
Registrar:       Name.com LLC

Expiration Date: 2015-12-26 19:18:07
Creation Date:   2003-12-26 19:18:07

Name Servers:
        ns1.serverfault.com
        ns2.serverfault.com
        ns3.serverfault.com
        ns4.serverfault.com

REGISTRANT CONTACT INFO
Stack Exchange, Inc.
Sysadmin Team
1 Exchange Plaza
Floor 26
New York
NY
10006
US
Phone:         +1.2122328280
Email Address: [email protected]

ADMINISTRATIVE CONTACT INFO
Stack Exchange, Inc.
Sysadmin Team
1 Exchange Plaza
Floor 26
New York
NY
10006
US
Phone:         +1.2122328280
Email Address: [email protected]

TECHNICAL CONTACT INFO
Stack Exchange, Inc.
Sysadmin Team
1 Exchange Plaza
Floor 26
New York
NY
10006
US
Phone:         +1.2122328280
Email Address: [email protected]

BILLING CONTACT INFO
Stack Exchange, Inc.
Sysadmin Team
1 Exchange Plaza
Floor 26
New York
NY
10006
US
Phone:         +1.2122328280
Email Address: [email protected]

Timestamp: 1363827248.6992

The Data in the Name.com LLC WHOIS database is provided by Name.com LLC for information purposes, and to assist persons in obtaining information about or related to a domain name registration record.  Name.com LLC does not guarantee its accuracy.  By submitting a WHOIS query, you agree that you will use this Data only for lawful purposes and that, under no circumstances will you use this Data to:  (1) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via e-mail (spam); or (2) enable high volume, automated, electronic processes that apply to Name.com LLC (or its systems). Name.com LLC reserves the right to modify these terms at any time.  By submitting this query, you agree to abide by this policy.

Cached on: 2013-03-20T18:54:08-06:00

What I need to do is extract certain information from each query. The problem is that I don't understand how to extract just the contact emails from each domain whois because each whois result is different depending on the registrar.

For example, this is how I'd like it to work:

Through command line my server should check the whois information for each domain name and export all the results to a new text file that would just contain the email addresses for the owners of the domain name. The name of the file containing all the domains is domains.txt and I would like the new file to be named new.txt if possible.

Any help with this would be greatly appreciated. Thanks in advance!

Upvotes: 4

Views: 6142

Answers (2)

cmrust
cmrust

Reputation: 366

Not necessarily Perl, but since you are doing this on the command line (presumably linux) you can use a shell script to do the following.

cat domain.txt | while read line
do
echo "$line - `whois $line | grep \"@\"`" >> new.txt
done

If your domain.txt file looks like:

stackoverflow.com

Then your new.txt will look something like:

stackoverflow.com - [email protected]
stackoverflow.com - [email protected]
stackoverflow.com - [email protected]
stackoverflow.com - [email protected]

You could add in some 'sort' and 'uniq' commands to clean up the repeated values. Let me know if necessary and I'll elaborate.

Upvotes: 0

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185700

You first things should do search whois on cpan and then pick up the less outdated and the most ratted and the most relevant.

Upvotes: 1

Related Questions