Created
March 14, 2011 20:29
-
-
Save creaktive/869814 to your computer and use it in GitHub Desktop.
Tor::Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| package Tor::Control; | |
| use strict; | |
| use utf8; | |
| use warnings 'all'; | |
| use IO::Socket; | |
| use Moose; | |
| has host => (is => 'rw', isa => 'Str', default => 'localhost'); | |
| has port => (is => 'rw', isa => 'Int', default => 9050); | |
| has ctlport => (is => 'rw', isa => 'Int', default => 9051); | |
| sub reset { | |
| my ($self) = @_; | |
| $self->cmd([ 'AUTHENTICATE', 'signal NEWNYM', 'quit', ]); | |
| } | |
| =head2 cmd($cmd) | |
| Envia o(s) comando(s) para o daemon do Tor. $cmd pode ser referência a um array de comandos. O "line ending" correto é adicionado automaticamente. | |
| =cut | |
| sub cmd { | |
| my ($self, $cmd) = @_; | |
| my $sock = new IO::Socket::INET( | |
| Proto => 'tcp', | |
| PeerAddr => $self->host, | |
| PeerPort => $self->ctlport, | |
| ) or return 0; | |
| $sock->autoflush(1); | |
| if (ref($cmd) eq 'ARRAY') { | |
| foreach (@{$cmd}) { | |
| chomp; | |
| $_ .= "\015\012"; | |
| $sock->send($_); | |
| } | |
| } else { | |
| chomp $cmd; | |
| $cmd .= "\015\012"; | |
| $sock->send($cmd); | |
| } | |
| $sock->shutdown(2); | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment