olegwtf / p5-io-socket-socks-wrapper Goto Github PK
View Code? Open in Web Editor NEWAllow any perl package to work through a SOCKS proxy
Home Page: http://search.cpan.org/perldoc?IO::Socket::Socks::Wrapper
Allow any perl package to work through a SOCKS proxy
Home Page: http://search.cpan.org/perldoc?IO::Socket::Socks::Wrapper
IO::Socket::Socks::Wrapper =========================================== IO::Socket::Socks::Wrapper allows to wrap up the network connections into socks proxy. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: IO::Socket::Socks COPYRIGHT AND LICENCE Oleg G This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
First, my apologies if this is addressed in a newer version - we have
IO::Socket:Socks v. 0.67
IO::Socket::Socks::Wrapper v. 0.14
The wrapper is applied globally before any other connection related libs are included:
require IO::Socket::Socks::Wrapper;
IO::Socket::Socks::Wrapper->import({ProxyAddr => $Socks5Host,
ProxyPort => $Socks5Port,
Timeout => 30,
SocksDebug => 0});
The file where this happens calls a second file that loops over connecting to a number of devices with the following code:
use Net::Telnet;
my $telnet = new Net::Telnet(
Timeout => 2,
Cmd_remove_mode => 1,
Errmode => 'return',
Dump_Log => $DebugLog,
Prompt => '/-->\s*$/i'
);
my $error;
# Ok, open the connection
if(!$telnet->open($self->{'ip'})) {
$error="Could not connect to ONT ($self->{'ip'}) - " . $telnet->errmsg();
return (0,$error);
}
If any of these devices happen to not be online, and open() times out, it does not return $error, but instead exits back to the first file.
We need ability to use IO::Socket::Socks::Wrapper with non-blocking event loops like POE, anyevent, Mojo::IOLoop and so on
The idea is:
tie $socket inside _connect()
In Tie class FILENO() should return fileno to fake file descriptor which will return non-ready status for write (and maybe read) when asking whith select/poll/etc while socks handshake not done. Here some ideas how to create such file descriptor: http://www.linux.org.ru/forum/development/10772549?lastmod=1408291493471. At the same time we should start making non-blocking socks handshake inside _connect(), adding appropriate polling for event loop. User of the module should set how to do proper poll inside this event loop with config like this (examples for Mojo::IOLoop and AnyEvent):
{
init_io_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->io($hdl => sub {
my $writable = pop;
if ($writable) {
$writable_cb->();
}
else {
$readable_cb->();
}
})
},
set_read_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->watch($hdl, 1, 0);
},
unset_read_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 0);
},
set_write_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 1);
},
unset_write_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->watch($hdl, 0, 0);
},
destroy_io_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
Mojo::IOLoop->singleton->reactor->remove($hdl);
}
}
{
my $w;
init_io_watcher => undef,
set_read_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
$w = AnyEvent->io(
fh => $hdl,
poll => 'r',
cb => sub {
$readable_cb->();
}
)
},
unset_read_watcher => sub {
undef $w;
},
set_write_watcher => sub {
my ($hdl, $readable_cb, $writable_cb) = @_;
$w = AnyEvent->io(
$fh => $hdl,
poll => 'w',
cb => sub {
$writable_cb->();
}
);
},
unset_write_watcher => sub {
undef $w;
},
destroy_io_watcher => undef
}
After socks handshake done we will make dup2(io_socket_socks_fd, fake_fd). So, now fake_fd is real fd of the socket and will indicate as ready for write().
It looks like it works with IO::Socket::IP
version 0.35, but stops working at 0.36 and 0.37.
Hello and my appologies for stealing your time with this probably stupid question, I am not into Network Programming at all.^^
The Problem I am trying to solve is about connecting to a LDAP Server through a Socks Proxy, with no local name Resolution possible.
here is the relevant code:
IO::Socket::Socks::Wrapper->import( 'Net::LDAP::connect_ldap()' => { ProxyAddr => $proxy, ProxyPort => $proxy_port, Timeout => 5, SocksDebug => 0 } ); my $ldap = Net::LDAP->new($ldap_uri); if (!$ldap) { _debug(2, "could not establish connection: $@"); return 0; }
I thought that the name Resolution is automatically done by the Proxy Server, but i get this Error from my debug output
...could not establish connection: IO::Socket::INET: Bad hostname 'somehost.com'
Setting local names in /etc/hosts does solve that issue but its not the way it should work.
Am I using your module wrong or do i have to lookup the names before hand through the proxy and pass the ip to ldap connection?
Thank you very much in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.