Provides an interface to a remote host through a field of differing proxy types. Socks5, connect, http, and cgi (web based) proxies are currently supported.


Net::ProxyGlue lets the user build and send data through a chain of varying types of proxy servers with different levels to randomly select from. After a chain is built, the connection is set up to read and write to the remote destination through the chain. Data can then be sent and received as if the chain didn't exist, but the user is limited to http requests if there are cgi or http proxies anywhere in the chain.


Net::ProxyGlue comes with the following methods:

$chain = Net::ProxyGlue->new( %options )
This method creates and returns a new Net::ProxyGlue object. Key/value pairs will be forwarded to the grow() method, and are not required. See $chain->grow for more information.

$chain->grow( %options )
This will add a proxy to chain with the following possible arguments: ( Only addr is required to be supplied, the rest are provided in order to keep track of various proxy attributes or for more control. )

  addr => address of remote proxy in the form "host:port"

  type => type of proxy service offered
    socks5, connect, http, and cgi supported; defaults to socks5

  country => country the proxy resides in

  desc => description of the proxy

  pos => add the proxy to this level in the chain
    If pos isn't specified, the proxy will be placed at the end.

  take_pos => whether to move the other proxies potentially residing at pos
    aside or to join up with them and be seleted randomly when path selection
    occurs; 1 or a 0, default is 1

Proxy chains must be in the order (socks|connect)* -> http? -> cgi* to work properly.

$chain->drop( $addr )
Delete all proxies in the chain that have an addr attribute $addr, which is a string in the form ``host:port''.

$chain->load_list( @list )
Load @list, an array of hashes, directly as the chain data. The order of the hashes is unimportant, because the order is derived from the pos key. For more information, look at $chain->dump_list.

in this hash, No error checking is done on the list, so be sure the order is correct and enough keys are specified beforehand, or else you might get unexpected errors.

Return the array of all the proxy hashes, in no particular order: the order is determined by the pos of the hash element. The keys are all the arguments to $chain->grow, minus take_pos.

Return a string with the chain data in the follwing format:

This method is an easy way to save to and load chain data from disk.

The order of the actual chain array is completely arbitrary. Use this function to generate a path through the field (one proxy randomly chosen from each level), where the array returned is the locations of the proxies in the chain array.

This is like $chain-get_order>, but it returns all the proxies in every field in order.

$chain->connect( $dest )
Setup the chain so that the last proxy will connect to $dest, with all data relayed through the chain. $dest is in the format host:port

$chain->send( $string )
Send data to the remote destination ( provided during $chain->connect ) through the chain. Only send HTTP requests through chains with CGI and HTTP proxies or else you might get unexpected results.

$chain->read( $length )
Return $length bytes from the remote socket. If $length isn't provided, return the equivilent of <$sock>.

my $sock = $chain->{``sock''}
If you would like to access the sock directly, after you have called $chain->connect(), do:
  my $sock = $chain->{"sock"};

However, using the resulting $sock to send data will generate wildly error-prone requests for chains with HTTP and CGI proxies, so it is highly recommended you only use this method for reading, if at all.

Close the connection to the chain.

This method will return the last error message for a chain object. Useful error messages are available for $chain->connect, $chain->grow, and $chain->new when they return 0.


Template Client

  #! /usr/bin/perl
  # Very template example, only 1 proxy per level
  # Get the destination and build the list out of @ARGV, then connect
  # to $dest, send data, and print the response.
  use Net::ProxyGlue;
  my $dest = shift @ARGV;
  my $chain = Net::ProxyGlue->new;
  foreach my $proxy (@ARGV)
    my ($addr, $type) = split(m/-/, $proxy);
      addr => $addr,
      type => $type
  $chain->connect($dest) || die($chain->error."\n");
  # fill in "... data ..." with whatever yourself
  $chain->send(" ... data ... ");
  print $line while (my $line = $chain->read);


Add https, ssh tunnelling, and authentication procedures.


James Halliday ( )


Copyright (c) 2005 James Halliday. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GPL.