[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] DNS-host-resolution-for-tls_handshake
commit 0f855458315fcb2838b630c1f17eb83bebb7a5cf
Author: Arun Pandian G <arunpandianp@xxxxxxxxx>
Date: Thu Feb 6 17:38:00 2014 +0530
DNS-host-resolution-for-tls_handshake
---
ooni/nettests/experimental/tls_handshake.py | 28 ++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/ooni/nettests/experimental/tls_handshake.py b/ooni/nettests/experimental/tls_handshake.py
index c3da9a9..7da291a 100644
--- a/ooni/nettests/experimental/tls_handshake.py
+++ b/ooni/nettests/experimental/tls_handshake.py
@@ -23,6 +23,8 @@
from socket import error as socket_error
from socket import timeout as socket_timeout
+from socket import inet_aton as socket_inet_aton
+from socket import gethostbyname as socket_gethostbyname
from time import sleep
import os
@@ -105,6 +107,10 @@ class HostUnreachableError(Exception):
"""Raised when the host IP address appears to be unreachable."""
pass
+class HostUnresolveableError(Exception):
+ """Raised when the host IP address appears to be unreachable."""
+ pass
+
class ConnectionTimeout(Exception):
"""Raised when we receive a :class:`socket.timeout <timeout>`, in order to
pass the Exception along to
@@ -212,9 +218,26 @@ class HandshakeTest(nettest.NetTestCase):
## We have to set the default timeout on our sockets before creation:
socket.setdefaulttimeout(self.timeout)
+ def isIP(self,addr):
+ try:
+ socket_inet_aton(addr)
+ return True
+ except socket_error:
+ return False
+
+ def resolveHost(self,addr):
+ try:
+ return socket_gethostbyname(addr)
+ except socket_error:
+ raise HostUnresolveableError
def splitInput(self, input):
addr, port = input.strip().rsplit(':', 1)
+
+ #if addr is hostname it is resolved to ip
+ if not self.isIP(addr):
+ addr=self.resolveHost(addr)
+
if self.localOptions['port']:
port = self.localOptions['port']
return (str(addr), int(port))
@@ -227,7 +250,10 @@ class HandshakeTest(nettest.NetTestCase):
for line in fh.readlines():
if line.startswith('#'):
continue
- yield self.splitInput(line)
+ try:
+ yield self.splitInput(line)
+ except HostUnresolveableError:
+ continue
def buildSocket(self, addr):
global s
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits