簡體   English   中英

如何在 Perl 中實現簡單的 WHOIS 代理?

[英]How can I implement a simple WHOIS proxy in Perl?

我有幾個WHOIS服務器,我想為其設置一個代理。 代理應根據查詢中的數據將請求轉發到適當的服務器。 如何解決這個問題?

第 1 步閱讀WHOIS 的 RFC
步驟 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:85519846801225-959797@whoisprivacyservices.com.au
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:85519846801225-959797@whoisprivacyservices.com.au
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:85519846801225-959797@whoisprivacyservices.com.au
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

我不是 whois 方面的專家,但Net::Whois::Proxy似乎是您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM