Net::Proxy(3pm) | User Contributed Perl Documentation | Net::Proxy(3pm) |
Net::Proxy - Framework for proxying network connections in many ways
use Net::Proxy; # proxy connections from localhost:6789 to remotehost:9876 # using standard TCP connections my $proxy = Net::Proxy->new( { in => { type => 'tcp', port => '6789' }, out => { type => 'tcp', host => 'remotehost', port => '9876' }, } ); # register the proxy object $proxy->register(); # and you can setup multiple proxies # and now proxy connections indefinitely Net::Proxy->mainloop();
A "Net::Proxy" object represents a proxy that accepts connections and then relays the data transfered between the source and the destination.
The goal of this module is to abstract the different methods used to connect from the proxy to the destination.
A proxy is a program that transfer data across a network boundary between a client and a server. "Net::Proxy" introduces the concept of "connectors" (implemented as "Net::Proxy::Connector" subclasses), which abstract the server part (connected to the client) and the client part (connected to the server) of the proxy.
This architecture makes it easy to implement specific techniques to cross a given network boundary, possibly by using a proxy on one side of the network fence, and a reverse-proxy on the other side of the fence.
See "AVAILABLE CONNECTORS" for details about the existing connectors.
If you only intend to use "Net::Proxy" and not write new connectors, you only need to know about "new()", "register()" and "mainloop()".
The connector parameters are described in the table below, as well as in each connector documentation.
If $max_connections is given, the proxy will stop after having fully processed that many connections. Otherwise, this method does not return.
(Note: throughout the "Net::Proxy" source code, calls to "debug()" are commented with "##".)
Some of the class methods are related to the socket objects that handle the actual connections.
The following methods manage some statistical information about the individual proxies:
All connection types are provided with the help of specialised classes. The logic for protocol "xxx" is provided by the "Net::Proxy::Connector::xxx" class.
There is a single parameter that all connectors accept: "hook". Given a code reference, the code reference will be called when data is received on the corresponding socket.
The code reference should have the following signature:
sub callback { my ($dataref, $sock, $connector) = @_; ... }
$dataref is a reference to the chunk of data received, $sock is a reference to the socket that received the data, and $connector is the "Net::Proxy::Connector" object that created the socket. This allows someone to eventually store data in a stash stored in the connector, so as to share data between sockets.
This is the simplest possible proxy connector. On the "in" side, it sits waiting for incoming connections, and on the "out" side, it connects to the configured host/port.
This proxy connector can connect to a TCP server though a web proxy that accepts HTTP CONNECT requests.
This proxy connector is a Y-shaped connector: depending on the client behaviour right after the connection is established, it connects it to one of two services, handled by two distinct connectors.
This proxy connector does nothing. You can use it as a template for writing new "Net::Proxy::Connector" classes.
This table summarises all the available "Net::Proxy::Connector" classes and the parameters their constructors recognise.
"N/A" means that the given "Net::Proxy::Connector" cannot be used in that position (either "in" or "out").
Connector | in parameters | out parameters ------------+-----------------+----------------- tcp | host | host | port | port ------------+-----------------+----------------- connect | N/A | host | | port | | proxy_host | | proxy_port | | proxy_user | | proxy_pass | | proxy_agent ------------+-----------------+----------------- dual | host | N/A | port | | timeout | | server_first | | client_first | ------------+-----------------+----------------- dummy | N/A | N/A ------------+-----------------+----------------- ssl | host | host | port | port | start_cleartext | start_cleartext ------------+-----------------+----------------- connect_ssl| N/A | host | | port | | proxy_host | | proxy_port | | proxy_user | | proxy_pass | | proxy_agent
"Net::Proxy::Connector::dummy" is used as the "out" parameter for a "Net::Proxy::Connector::dual", since the later is linked to two different connector objects.
Philippe 'BooK' Bruhat, "<book@cpan.org>".
Please report any bugs or feature requests to "bug-net-proxy@rt.cpan.org", or through the web interface at <http://rt.cpan.org/>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
Here's my own wishlist:
This one will probably be named "Net::Proxy::Connector::httptunnel".
This is probably impossible with "Net::Proxy", since the FEP driver is a rather low-level driver (at the IP level of the network stack).
See <http://savannah.nongnu.org/projects/nstx/>, OzymanDNS, <http://www.doxpara.com/slides/BH_EU_05-Kaminsky.pdf>. <http://thomer.com/howtos/nstx.html> for examples.
See <http://www.linuxexposed.com/Articles/Hacking/Case-of-a-wireless-hack.html>, <http://sourceforge.net/projects/itun>, <http://www.cs.uit.no/~daniels/PingTunnel/>, <http://thomer.com/icmptx/> for examples.
Since ICMP implies low-level packet reading and writing, it may not be possible for "Net::Proxy" to handle it.
Look also here: <http://gray-world.net/tools/>
Martin Werthmoeller provided a full implementation of a connector that can handle IMAP connections and upgrade them to TLS if the client sends a "STARTTLS" command. My implementation will split this in two parts "Net::Proxy::Connector::ssl" and "Net::Proxy::Connector::starttls", that inherits from the former.
You can find documentation for this module with the perldoc command.
perldoc Net::Proxy
You can also look for information at:
<http://listes.mongueurs.net/mailman/listinfo/net-proxy/>
This list receive an email for each commit
svn://svn.mongueurs.net/Net-Proxy/trunk/
Also available through a web interface at <http://svnweb.mongueurs.net/Net-Proxy>
<http://annocpan.org/dist/Net-Proxy>
<http://cpanratings.perl.org/d/Net-Proxy>
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Proxy>
<http://search.cpan.org/dist/Net-Proxy>
Copyright 2006-2007 Philippe 'BooK' Bruhat, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Hey! The above document had some coding errors, which are explained below:
2013-10-03 | perl v5.18.1 |