Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Tor cant access localhost pages

I have Tor running and a python script to get web pages:

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket

print urllib2.urlopen(URL).read()

However, if the URL is

http://localhost/some_page.html

I get the following error:

raise Socks5Error(ord(resp[1]),_generalerrors[ord(resp[1])])
TypeError: __init__() takes exactly 2 arguments (3 given)

Can someone explain to me what exactly happens?

Thank you.

like image 493
Veni_Vidi_Vici Avatar asked Oct 25 '12 00:10

Veni_Vidi_Vici


People also ask

Why is Tor Browser not connecting?

If Tor Browser was working before and is not working now your system may have been hibernating. A reboot of your system will solve the issue. Delete Tor Browser and install it again. If updating, do not just overwrite your previous Tor Browser files; ensure they are fully deleted beforehand.


2 Answers

It is the way protocol is designed. When you send a request, it is transported to another machine on Internet with Socks5 envelope. So actual request is made from external server, thus accessing 127.0.0.1 is not possible.

like image 73
Supreet Sethi Avatar answered Oct 27 '22 17:10

Supreet Sethi


You can use Tor proxy with php in localhost. Using cURL. Put your local IP on LAN proxy config "No proxy for:". Exammple 192.168.1.10. Then call your php as "http://192.168.1.10/your_script.php"

$proxy = '127.0.0.1:9150';
$ur = "http://anydomain.com";
$ch = curl_init();

curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_URL, $ur);

    $curl_scraped_page = curl_exec($ch);
    $error = curl_error($ch);
like image 22
Santo Avatar answered Oct 27 '22 17:10

Santo