From 7c6dfb1e4cc99edbf65e671e28284be302c56759 Mon Sep 17 00:00:00 2001 From: Roman Hergenreder Date: Mon, 27 Mar 2023 06:36:38 -0400 Subject: [PATCH] getAddress fix --- test_ciphers.sh | 26 -------------------------- util.py | 9 ++++++++- 2 files changed, 8 insertions(+), 27 deletions(-) delete mode 100755 test_ciphers.sh diff --git a/test_ciphers.sh b/test_ciphers.sh deleted file mode 100755 index 54e9a7e..0000000 --- a/test_ciphers.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# OpenSSL requires the port number. -SERVER=$1 -DELAY=1 -ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g') - -echo Obtaining cipher list from $(openssl version). - -for cipher in ${ciphers[@]} -do -echo -n Testing $cipher... -result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1) -if [[ "$result" =~ ":error:" ]] ; then - error=$(echo -n $result | cut -d':' -f6) - echo NO \($error\) -else - if [[ "$result" =~ "Cipher is ${cipher}" || "$result" =~ "Cipher :" ]] ; then - echo YES - else - echo UNKNOWN RESPONSE - echo $result - fi -fi -sleep $DELAY -done diff --git a/util.py b/util.py index ede4ed4..5d00249 100755 --- a/util.py +++ b/util.py @@ -14,7 +14,14 @@ def isPortInUse(port): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: return s.connect_ex(('127.0.0.1', port)) == 0 -def get_address(interface="tun0"): +def get_address(interface={"tun0", "vpn0"}): + if not isinstance(interface, str): + requested = set(interface) + available = set(ni.interfaces()) + interfaces = list(requested.intersection(available)) + interface = None if not interfaces else interfaces[0] + + # not found or not specified, take the first available, which is not loopback if not interface in ni.interfaces(): interfaces = ni.interfaces() interfaces.remove('lo')