tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit 6cbfbc64a43432f595c750352c66065eb2de4175
parent 06e03f40cc8014ace861696e1089cbda15154638
Author: parazyd <parazyd@dyne.org>
Date:   Wed,  6 Mar 2019 16:27:35 +0100

Add echoserver Python examples.

Diffstat:
Acontrib/echo_recv.py | 38++++++++++++++++++++++++++++++++++++++
Acontrib/echo_send.py | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/contrib/echo_recv.py b/contrib/echo_recv.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# Copyright (c) 2019 Dyne.org Foundation +# tor-dam is written and maintained by Ivan Jelincic <parazyd@dyne.org> +# +# This file is part of tor-dam +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +from argparse import ArgumentParser +from socket import socket, AF_INET, SOCK_STREAM + +parser = ArgumentParser() +parser.add_argument('-l', '--listen', default='127.0.0.1') +parser.add_argument('-p', '--port', default=5000) +args = parser.parse_args() + +s = socket(AF_INET, SOCK_STREAM) +s.bind((args.listen, args.port)) +s.listen(1) + +conn, addr = s.accept() +while 1: + data = conn.recv(1024) + if not data: + break + print(data) + conn.send(data) +conn.close() diff --git a/contrib/echo_send.py b/contrib/echo_send.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# Copyright (c) 2019 Dyne.org Foundation +# tor-dam is written and maintained by Ivan Jelincic <parazyd@dyne.org> +# +# This file is part of tor-dam +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +from argparse import ArgumentParser +from socket import socket, AF_INET, SOCK_STREAM + +import socks + +parser = ArgumentParser() +parser.add_argument('-a', '--address', default='127.0.0.1') +parser.add_argument('-p', '--port', default=5000) +args = parser.parse_args() + +if '.onion' in args.address: + s = socks.socksocket(AF_INET, SOCK_STREAM) + s.set_proxy(socks.SOCKS5, "localhost", 9050) +else: + s = socket(AF_INET, SOCK_STREAM) + +s.connect((args.address, args.port)) +s.send(b'HELLO') +data = s.recv(1024) +s.close() + +print(data)