# MIT License
#
# Copyright (c) 2018 k1dd00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE

# -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vim: fileencoding=utf-8 tabstop=4 expandtab shiftwidth=4
# pylint: disable=C0103,C0301,W1202,W0212

import urllib2
from BeautifulSoup import BeautifulSOAP

class TorCheck(object):
    """
    The TorCheck class.

    This class checks the tor status and ip address
    """

    IP_CHECK_ENDPOINT = "http://icanhazip.com"
    TOR_CHECK_ENDPOINT = "https://check.torproject.org"
        
    def __init__(self):
        self.text_key = "congratulations"

    def check_ip(self):
        """
        Checks the ip address

        Returns
        -------
        ip: str
            The ip address
        """

        request = urllib2.urlopen(self.IP_CHECK_ENDPOINT)
        response = request.read()
        return response.strip()
    
    def check_tor_status(self):
        """
        Checks the tor status

        Returns
        -------
        status: Bool
            The tor status
        """

        html = urllib2.urlopen(self.TOR_CHECK_ENDPOINT).read()
        parsed_html = BeautifulSOAP(html)
        content = parsed_html.body.find('h1', attrs={'class':'not'}).text
        return self.text_key in content.lower()        

# MIT License
#
# Copyright (c) 2018 k1dd00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE

# -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vim: fileencoding=utf-8 tabstop=4 expandtab shiftwidth=4
# pylint: disable=C0103,C0301,W1202,W0212

import urllib2
from BeautifulSoup import BeautifulSOAP

class TorCheck(object):
    """
    The TorCheck class.

    This class checks the tor status and ip address
    """

    IP_CHECK_ENDPOINT = "http://icanhazip.com"
    TOR_CHECK_ENDPOINT = "https://check.torproject.org"
        
    def __init__(self):
        self.text_key = "congratulations"

    def check_ip(self):
        """
        Checks the ip address

        Returns
        -------
        ip: str
            The ip address
        """

        request = urllib2.urlopen(self.IP_CHECK_ENDPOINT)
        response = request.read()
        return response.strip()
    
    def check_tor_status(self):
        """
        Checks the tor status

        Returns
        -------
        status: Bool
            The tor status
        """

        html = urllib2.urlopen(self.TOR_CHECK_ENDPOINT).read()
        parsed_html = BeautifulSOAP(html)
        content = parsed_html.body.find('h1', attrs={'class':'not'}).text
        return self.text_key in content.lower()        

# MIT License # # Copyright (c) 2018 k1dd00 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE # -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vim: fileencoding=utf-8 tabstop=4 expandtab shiftwidth=4 # pylint: disable=C0103,C0301,W1202,W0212 The TorCheck class.      This class checks the tor status and ip address Checks the ip address          Returns         -------         ip: str             The ip address Checks the tor status          Returns         -------         status: Bool             The tor status