2013-03-21 66 views
4

我的服務器上有一個很大的文本文件,裏面有一個我需要獲取聯繫信息的域列表。下面是這樣的例子網站顯示了我,當我在stackoverflow.com運行WHOIS查詢:如何使用命令行獲取whois信息?

[email protected] [~]# 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 

我需要做的是提取每個查詢的某些信息。問題是我不明白如何從每個域中提取聯繫人電子郵件,這是因爲每個whois結果因註冊服務商而異。

例如,這是我想它是如何工作的:

通過命令行我的服務器應該檢查每個域名的whois信息,所有的結果導出到,將只包含一個新的文本文件該域名所有者的電子郵件地址。包含所有域的文件的名稱是domains.txt,如果可能,我希望新文件被命名爲new.txt。

任何幫助,這將不勝感激。提前致謝!

回答

1

你第一件事應該做的搜索whois on cpan然後拿起過時不太老,最棘手和最相關的。

+1

我認爲您所鏈接的Net :: Whois :: IANA是用於獲取IP地址的whois,而不是域名。我錯了嗎?這看起來不像是回覆電子郵件地址和IANA控制IP分配,除非我誤解了某些東西,否則不是域名。 – syf101 2013-03-21 01:09:19

0

不一定是Perl,但是由於您是在命令行(假定是linux)上執行此操作,因此可以使用shell腳本執行以下操作。

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

如果您DOMAIN.txt文件文件看起來像:

stackoverflow.com 

然後你new.txt看起來像:

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

你可以在一些 '排序' 添加和' uniq'命令清理重複的值。如果有必要,讓我知道,我會詳細說明。