Commit eaf6d649 authored by anonym's avatar anonym

tor-controlport-filter: add --listen-interface.

Original commit by Joy SN <joysn1980@yahoo.com> for Whonix, fixing:
https://phabricator.whonix.org/T579

Will-fix: #12173
parent 95643a2a
......@@ -122,14 +122,17 @@
# clients.
import argparse
import fcntl
import glob
import ipaddress
import os.path
import psutil
import re
import socket
import socketserver
import stem
import stem.control
import struct
import sys
import textwrap
import yaml
......@@ -179,6 +182,15 @@ def exe_path_of_pid(pid):
return psutil.Process(pid).exe()
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', bytes(ifname[:15], 'utf-8'))
)[20:24])
class FilteredControlPortProxySession:
"""
Class used to deal with a single session, delegated from the handler
......@@ -661,6 +673,12 @@ def main():
help="specifies the port on which the server listens " +
"(default: {})".format(DEFAULT_LISTEN_PORT)
)
parser.add_argument(
"--listen-interface",
type=str, metavar='INTERFACE',
help="specifies the interface on which the server listens " +
"(default: NULL)"
)
parser.add_argument(
"--control-cookie-path",
type=str, metavar='PATH', default=DEFAULT_COOKIE_PATH,
......@@ -694,7 +712,14 @@ def main():
global_args.__dict__['print_requests'] = global_args.complain or \
global_args.debug
global_args.__dict__['print_responses'] = global_args.debug
address = (global_args.listen_address, global_args.listen_port)
if global_args.listen_interface:
ip_address = get_ip_address(global_args.listen_interface)
if global_args.debug:
log("IP address for interface {} : {}".format(
global_args.listen_interface,ip_address))
else:
ip_address = global_args.listen_address
address = (ip_address, global_args.listen_port)
server = FilteredControlPortProxy(address, FilteredControlPortProxyHandler)
log("Tor control port filter started, listening on {}:{}".format(*address))
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment