File: example

package info (click to toggle)
libnet-socks-perl 0.03-17
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 86; makefile: 2
file content (73 lines) | stat: -rwxr-xr-x 2,165 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl -w

use strict;

use Net::SOCKS;

sub usage {
    print "Usage:\n";
    print "\texample <socks_addr> <socks_port> <target_addr> <target_port>\n";
    print "to connect to <target_addr>:<target_port> through SOCKS5 at <socks_addr>:<socks_port>\n";
}

if ($#ARGV != 3) {
    &usage();
    exit(1);
}

my ($socks_addr, $socks_port, $target_addr, $target_port) = @ARGV;

print "Attempting to connect to $target_addr at port $target_port using the socks\n";
print "server at $socks_addr port $socks_port\n";

my $sock = new Net::SOCKS(socks_addr => $socks_addr,
		socks_port => $socks_port,
		#user_id => 'the_user',
		#user_password => 'the_password',
		#force_nonanonymous => 1, 
		protocol_version => 5);
my $f= $sock->connect(peer_addr => $target_addr, peer_port => $target_port);
print "connect status: ",
	Net::SOCKS::status_message($sock->param('status_num')), "\n";

if ($sock->param('status_num') == SOCKS_OKAY) {
  print $f "clintdw\n";
  while (<$f>) { print }
  $sock->close();
}

print "Attempting to listen() using the server at $socks_addr port $socks_port\n";

$sock = new Net::SOCKS(socks_addr => $socks_addr,
		socks_port => $socks_port,
		#user_id => 'the_user',
		#user_password => 'the_password',
		#force_nonanonymous => 1, 
		protocol_version => 5);

# We expect a connection from $target_addr:9999
# This is just for the sake of testing that the SOCKS proxy lets us
# listen: we of course won't initiate a connection from
# $target_addr:9999 (and in the majoirty of cases, we simply *can not*,
# since $target_addr is likely to be remote)
# --Seb
my ($ip, $ip_dot_dec, $port) = $sock->bind(peer_addr => $target_addr,
					   peer_port => 9999);
print "bind status: ",
	Net::SOCKS::status_message($sock->param('status_num')), "\n";

if ($sock->param('status_num') == SOCKS_OKAY) {
  print "Listening at the IP of ", $ip_dot_dec, " at port ", $port, "\n";

# Following is commented out, according to comment above.
#  $f= $sock->accept();
#}
#print "accept status: ",
#	Net::SOCKS::status_message($sock->param('status_num')), "\n";
#
#if ($sock->param('status_num') == SOCKS_OKAY) {
#  while (<$f>) { print }
#}
}
$sock->close();