0

I'm using TOR proxy to connect to Twython. But I saw that when I use a false ip:port like 666.666.666.666:666666 it still connects. So, how I can ensure/assert that I'm connected behind the proxy while using twython ?

from twython import Twython

client_args = {
    'proxies': {
        'socks5': '666.666.666.666:666666', # My TOR is 127.0.0.1:9000

    },
    'timeout': 300,
}

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, 
                  OAUTH_TOKEN_SECRET, client_args=client_args)

I also tried listening port 9000 with sudo tcpflow -i any -C -J port 9000 but it gets traffic when I'm not running twython too... so it's unconclusive.

Jeflopo
  • 2,192
  • 4
  • 34
  • 46

1 Answers1

0

you could create an IP checking method, as so:

import urllib
import re

def IpCheck(request):
    theIP = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request)
    ip = ''.join(theIP)
    return ip

url = 'http://checkip.dyndns.org'
realip = IpCheck(urllib.urlopen(url).read())
torip = IpCheck(#method that properly reads the website with tor like above) #I dont use twython 

set up your proxy, and then check the ip again through the proxy you are using.

Then you could check if the Ip's are the same with either

if realip == torip:
    print('Tor Isn't Working!')
else:
    print('Tor Enabled')

or a function:

def TorCheck(realip, torip):
    if realip == torip:
        return('Whatever you want it to return')
    else:
        return('Tor Is Enabled!')

or make it all one function:

def IpCheck(request, torrequest):
    theIP = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request)
    torip = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", torrequest)
    ip = ''.join(theIP)
    tip= ''.join(torip)
    if tip == ip:
        return('Whatever you want it to return')
    else:
        return('Tor Is Enabled!')# + 'Using Ip: ' + tip)
realip = urllib.urlopen(url).read()
torip = #Tor method that reads the website var url
#isTor = IpCheck(realip, torip)
#print IpCheck(realip, torip)
#or print isTor
Ben Morris
  • 606
  • 5
  • 24
  • Thanks, But this IS NOT the problem. My TOR instance works and I know my IP's. The question is, How I can check that Twython is behind my proxy If when I try with an imposible `ip:port` like `666.666.666.666:666666` it still works... :$ What guarantees that i'm behind a proxy and not using my own connection ? – Jeflopo Mar 02 '15 at 22:21