我有幾臺WHOIS服務器,我想要一個代理服務器。代理應根據查詢中的數據將請求轉發給適當的服務器。如何解決這個問題?如何在Perl中實現簡單的WHOIS代理?
4
A
回答
6
第1步閱讀RFC for WHOIS
第2步實現模擬服務器Net::Server
第3步使用您的模擬服務器和Net::Whois::Proxy或一些其他的WHOIS模塊實現代理
RFC的快速掃描似乎在說它只是一個簡單的基於文本的協議,需要一個CRLF終止行,然後發送一個CRLF終止行並關閉套接字。
是的,這真的看起來那麼簡單,因爲這個代碼
#!/usr/bin/perl
{
package Whois;
use strict;
use warnings;
use parent 'Net::Server';
sub process_request {
my $request = <>;
print "you sent me $request";
}
}
Whois->run;
你可以說
whois -h localhost -p 20203 foo.com
,並取回
you sent me foo.com
鑑於 「高負荷」 標籤當您完成測試時,您可能會想要切換到Net::Server::PreForkSimple
個性。
而只是因爲我很無聊:
#!/usr/bin/perl
package Whois {
use strict;
use warnings;
use parent 'Net::Server::PreFork';
use Net::Whois::Raw;
my %handler = (
org => "whois.publicinterestregistry.net",
);
sub process_request {
(my $request = <>) =~ s/[.]([^.]+)\x{0d}\x{0a}/.$1/;
print exists $handler{$1} ?
whois $request, $handler{$1} :
"I don't know where to look for $request\r\n";
}
}
Whois->run(
user => "nobody",
group => "nobody",
port => 43,
min_servers => 1, #min number of children
max_servers => 10, #max number of children
min_spare_servers => 1, #fork if we don't have this many waiting
max_spare_servers => 5, #kill if we have this many waiting
max_requests => 10_000, #num of requests before killing a child
);
,當我運行
sudo perl whois.pl
然後
whois -h localhost foo.org
給我們
NOTICE: Access to .ORG WHOIS information is provided to assist persons in
determining the contents of a domain name registration record in the Public Interest Registry
registry database. The data in this record is provided by Public Interest Registry
for informational purposes only, and Public Interest Registry does not guarantee its
accuracy. This service is intended only for query-based access. You agree
that you will use this data only for lawful purposes and that, under no
circumstances will you use this data to: (a) allow, enable, or otherwise
support the transmission by e-mail, telephone, or facsimile of mass
unsolicited, commercial advertising or solicitations to entities other than
the data recipient's own existing customers; or (b) enable high volume,
automated, electronic processes that send queries or data to the systems of
Registry Operator or any ICANN-Accredited Registrar, except as reasonably
necessary to register domain names or modify existing registrations. All
rights reserved. Public Interest Registry reserves the right to modify these terms at any
time. By submitting this query, you agree to abide by this policy.
Domain ID:D1608104-LROR
Domain Name:FOO.ORG
Created On:10-Jan-1995 05:00:00 UTC
Last Updated On:07-Mar-2011 00:26:43 UTC
Expiration Date:09-Jan-2012 05:00:00 UTC
Sponsoring Registrar:Fabulous.com Pty Ltd. (R133-LROR)
Status:CLIENT DELETE PROHIBITED
Status:CLIENT TRANSFER PROHIBITED
Registrant ID:fabwpp-000700385
Registrant Name:Domain Hostmaster, CustomerID : 85519846801225
Registrant Organization:Whois Privacy Services Pty Ltd
Registrant Street1:PO Box 923
Registrant Street2:
Registrant Street3:
Registrant City:Fortitude Valley
Registrant State/Province:QLD
Registrant Postal Code:4006
Registrant Country:AU
Registrant Phone:+61.730070090
Registrant Phone Ext.:
Registrant FAX:+61.730070091
Registrant FAX Ext.:
Registrant Email:[email protected]
Admin ID:fabwpp-000700385
Admin Name:Domain Hostmaster, CustomerID : 85519846801225
Admin Organization:Whois Privacy Services Pty Ltd
Admin Street1:PO Box 923
Admin Street2:
Admin Street3:
Admin City:Fortitude Valley
Admin State/Province:QLD
Admin Postal Code:4006
Admin Country:AU
Admin Phone:+61.730070090
Admin Phone Ext.:
Admin FAX:+61.730070091
Admin FAX Ext.:
Admin Email:[email protected]
Tech ID:fabwpp-000700385
Tech Name:Domain Hostmaster, CustomerID : 85519846801225
Tech Organization:Whois Privacy Services Pty Ltd
Tech Street1:PO Box 923
Tech Street2:
Tech Street3:
Tech City:Fortitude Valley
Tech State/Province:QLD
Tech Postal Code:4006
Tech Country:AU
Tech Phone:+61.730070090
Tech Phone Ext.:
Tech FAX:+61.730070091
Tech FAX Ext.:
Tech Email:[email protected]
Name Server:NS1.HITFARM.COM
Name Server:NS2.HITFARM.COM
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
Name Server:
DNSSEC:Unsigned
whois.publicinterestregistry.net
-1
我並不是專家的whois,但Net::Whois::Proxy似乎是你想要的。
相關問題
- 1. 簡單的Perl代理
- 2. 如何在Perl中編寫簡單的HTTP代理?
- 3. 如何在perl中實現單例類?
- 4. 如何在Yii2中實現簡單的管理面板
- 5. 現代Perl:如何在AUTOLOAD()中實現重分派方法?
- 6. 用Java實現簡單的HTTPS代理應用程序?
- 7. 如何實現簡單的C++函數
- 8. MVP如何實現簡單的登錄
- 9. Java中的簡單代理
- 10. 如何在Perl中實現RESTful API?
- 11. 如何在perl中實現linux查詢?
- 12. 如何在Perl中實現Web服務?
- 13. 如何在Perl中實現Unix grep?
- 14. 在Perl中如何實現Tie :: IxHash?
- 15. 如何在Perl中實現數組?
- 16. 在c#中實現代理或裝飾類的最簡單方法是什麼?
- 17. 在C++中實現簡單的getopt
- 18. 在AS3中最簡單的onReleaseOutside實現?
- 19. 在Android中實現簡單的服務
- 20. 如何在Perl CGI中實現傻瓜證明unicode處理?
- 21. 在Perl中的unbless實現?
- 22. 在Rails中實現更簡單的find_by_ [attribute]代碼
- 23. 在Python中實現「最簡單的協議」僞代碼算法
- 24. 實現在Perl
- 25. 如何簡單地實現一個KeyListener?
- 26. 如何在IOS中實現簡單的搜索欄
- 27. 如何在android中實現簡單的無限傳送帶?
- 28. 如何在java中實現簡單分組的k-means
- 29. 如何在Xamarin PCL中實現簡單的進度條?
- 30. 如何在我的簡單應用程序中實現反射?
我不這麼認爲。儘管名稱,Net :: Whois :: Proxy似乎是whois _client_,根本不是代理。 – cjm
代理服務器將whois請求轉發給相應的真實服務器,即客戶端。它作爲一個服務器做的唯一事情就是監聽請求。 – Schwern
@Schwern:我需要代理原始請求,而不是重建它們。 – planetp