EzDevInfo.com

socks interview questions

Top socks frequently asked interview questions

How do I install Socks / SocksIPy on Ubuntu?

I am new to python and would like to install SocksIPy on Ubuntu (running within a VirtualBox vm). The README says to place the socks.py file into my lib/site-packages directory. I do not know where to locate this directory. The Terminal command python socks.py install from the root runs, but does not install correctly (error "No module named socks" when I run import socks in a python script)

SocksIPy link http://socksipy.sourceforge.net/

Can someone suggest a way to get socks/socksipy running on my machine? Thanks!


Source: (StackOverflow)

How to make python Requests work via socks proxy

I'm using the great Requests library in my Python script:

import requests
r = requests.get("some-site.com")
print r.text

I would like to use socks proxy. But Requests only supports HTTP proxy now.

How can I do that?


Source: (StackOverflow)

Advertisements

Difference between HTTP Proxy and SOCKS Proxy?

I understand that SOCKS proxy only establishes connection at TCP level while HTTP proxy interpret traffic at HTTP level. Thus SOCKS proxy can work for any kind of protocol but HTTP Proxy can only handle HTTP traffic. But why HTTP Proxy like Squid can support protocol like IRC, FTP ? And when use a HTTP Proxy for IRC or FTP connection, what specifically happen? Is there any metadata added to the package when sent to the proxy over http protocol ?

Thanks


Source: (StackOverflow)

Use WebClient with socks proxy

Is there any way to use a socks proxy with WebClient? Specifically with the DownloadString method that it provides?
I don't want to use any third party stuff like privoxy,freecap whatever and I can't use commercial libraries like those from Chilkat. I tried using stuff from http://www.mentalis.org/ in fact I used their WebRequest implementation but they don't seem to have something similar for WebClient.

Thank you.


Source: (StackOverflow)

Using urllib2 with SOCKS proxy

Is it possible to fetch pages with urllib2 through a SOCKS proxy on a one socks server per opener basic? I've seen the solution using setdefaultproxy method, but I need to have different socks in different openers.

So there is SocksiPy library, which works great, but it has to be used this way:

import socks
import socket
socket.socket = socks.socksocket
import urllib2
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "x.x.x.x", y)

That is, it sets the same proxy for ALL urllib2 requests. How can I have different proxies for different openers?


Source: (StackOverflow)

How to make HTTP request through a (tor) socks proxy using python?

I'm trying to make a HTTP request using python. I tried changing my windows system proxy (using inetcpl.cpl )

url = 'http://www.whatismyip.com'
request = urllib2.Request(url)
request.add_header('Cache-Control','max-age=0')
request.set_proxy('127.0.0.1:9050', 'socks')
response = urllib2.urlopen(request)
response.read()

is giving me the error

Traceback (most recent call last): File "", line 1, in response = urllib2.urlopen(request) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 423, in _open 'unknown_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1240, in unknown_open raise URLError('unknown url type: %s' % type) URLError:


Source: (StackOverflow)

How to run multiple Tor processes at once with different exit IPs?

I am brand new to Tor and I feel like multiple Tors should be considered. The multiple tors I mentioned here are not only multiple instances, but also using different proxy ports for each, like what has been done here http://www.howtoforge.com/ultimate-security-proxy-with-tor)

I am trying to get started with 4 Tors. However, the tutorial applies only to Arch Linux and I am using a headless EC2 ubuntu 64bits. It is really a pain going through the differences between Arch and Ubuntu. And here I am wondering is there anyone could offer some help to implement my idea simplicitly.

  1. Four Tors running at the same time each with an individual port, privoxy or polipo or whatever are ok once it works. Like: 8118 <- Privoxy <- TOR <- 9050 8129 <- Privoxy <- TOR <- 9150 8230 <- Privoxy <- TOR <- 9250 8321 <- Privoxy <- TOR <- 9350

  2. In this way, if I try to return the ip of 127.0.0.1:8118, 8129, 8230 and 8321, they should return four different ips, which indicates there are four different Tors running at the same time. Then, a few minutes later, check again, all four of them should have a new ips again.

I know my simple 'dream' could come true in many ways, however... I am not only new to Tor, but even also to bash and python... That is why I come here and see whether some of you could light me up.

These links might be useful:

http://blog.databigbang.com/distributed-scraping-with-multiple-tor-circuits/ https://www.torservers.net/wiki/setup/server#multiple_tor_processes Best,

btw, if I run $ ps -A | grep 'tor' i have several instances there, however with "?" under the tty column, what does that mean since I know tty means terminals?


Source: (StackOverflow)

How to disable debug messages on sockjs- STOMP

I have the follow situation:

 var options = {
        protocols_whitelist : [ "websocket", "xhr-streaming", "xdr-streaming", "xhr-polling", "xdr-polling", "iframe-htmlfile", "iframe-eventsource", "iframe-xhr-polling" ],
        debug : false
    };

    var socket = new SockJS("/mmyurl/",undefined,options);
    var stompClient = Stomp.over(socket);
    stompClient.connect({
        company : "XXXXX"
    }, function(frame) {
        stompClient.subscribe('/topic/mytopic', function(message){ 
            var myitem = JSON.parse(message.body);

        });

all works fine, the problem is that on the javascript console is full of debug messages like this:

<<< MESSAGE
content-type:application/json;charset=UTF-8
subscription:sub-1
message-id:o6g660dt-113
destination:/topic/mytopic
content-length:411

And I want to disable the messages.

I tried to change some option and also tried to register simply:

var socket = new SockJS("/mmyurl/");

but it doesn't work.

Is there a way to disable the debug messages?

Any help is appreciated


Source: (StackOverflow)

Socks Proxy for HttpWebRequest

According to my research whilst trying to solve this problem, it turns out that the .Net WebProxy class does not support Socks proxies - a tad annoying. I also can't seem to find any code or information which explains how to implement Socks 4/5 support via a class which can easily be used with HttpWebRequest (the Proxy property, to be exact).

I've found limited information via google on how I could do this. One suggestion involves changing internet explorer proxy settings - something I'd rather not do.

Does anyone know of anything which could do the job or have any suggestions? Any help would be much appreciated.


Source: (StackOverflow)

How to use a TurnSocket (XEP-0065: SOCKS5 Bytestreams) connection? XEP-0096: SI File Transfer? [socket writeData]?

I'm attempting file transfer via XMPP on iOS using the XMPPFramework and OpenFire. The base of my code is from the following tutorial. I have a successful TurnSocket (XEP-0065: SOCKS5 Bytestreams) connection, but I can't work how to use it to send data. There are 2 considerations I have, both of which I am stuck on: 1. Calling [socket writeData] and 2. Using 'XEP-0096: SI File Transfer'.

Possible solution 1 - Calling [socket writeData] In my App delegate I have a didSucceed method. I can call [socket writeData] like this ...

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {

    NSLog(@"TURN Connection succeeded!");

    [socket writeData:myData withTimeout:60.0f tag:0]; 
    [turnSockets removeObject:sender];
}

Updated 14th June : Is this correct? If so, how does the other user read the data? I have tried implementing

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag

but it never gets called. How do I ensure it gets called?

Possible solution 2 - XEP-0096: SI File Transfer Do I need to use XEP-0096: SI File Transfer? If so, how do I use my successful connection within the XEP-0096 XML I need to form? The XEP-0096 docs imply there is a 'hash' attribute, but I don't know where this comes from.

e.g.

<iq type='set' id='offer1' to='receiver@jabber.org/resource'>
  <si xmlns='http://jabber.org/protocol/si' 
      id='a0'
      mime-type='text/plain'
      profile='http://jabber.org/protocol/si/profile/file-transfer'>
    <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'
          name='test.txt'
          size='1022'
          hash='552da749930852c69ae5d2141d3766b1'
          date='1969-07-21T02:56:15Z'>
      <desc>This is a test. If this were a real file...</desc>
    </file>
    <feature xmlns='http://jabber.org/protocol/feature-neg'>
      <x xmlns='jabber:x:data' type='form'>
        <field var='stream-method' type='list-single'>
          <option><value>http://jabber.org/protocol/bytestreams</value></option>
          <option><value>http://jabber.org/protocol/ibb</value></option>
        </field>
      </x>
    </feature>
  </si>
</iq>

Source: (StackOverflow)

cURL request using socks5 proxy fails when using PHP, but it works through the command line

cURL + proxy noob here, having a hard time. I'm having trouble trying to retrieve a web page from a remote secure server via a proxy. Everything has apparently been set up correctly by a remote dev, such that the following command line instruction works and returns what we're looking for:

curl -k --socks5-hostname localhost:xxxx https://hostname/

However, the following PHP does not echo the requested webpage. Instead it echoes the error 'Couldn't resolve host name':

$proxy = 'localhost:xxxx';
$url = 'https://hostname/';
//$proxyauth = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
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, $url);
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);

if ($error)
    echo $error;
elseif ($curl_scraped_page)
    echo $curl_scraped_page;

If the $url is changed to a public page, such as Google, the request is successful and everyone is happy.

The connection requires an SSH tunnel if that changes anything at all. The tunnel is open and functioning, as proven by the command line request succeeding.

Is there something obvious that is being missed here?


Source: (StackOverflow)

How to parse a raw HTTP response as HttpListenerResponse?

If I have a raw HTTP response as a string:

HTTP/1.1 200 OK
Date: Tue, 11 May 2010 07:28:30 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Server: gws
X-XSS-Protection: 1; mode=block
Connection: close

<!doctype html><html>...</html>

Is there an easy way I can parse it into an HttpListenerResponse object? Or at least some kind .NET object so I don't have to work with raw responses.

What I'm doing currently is extracting the header key/value pairs and setting them on the HttpListenerResponse. But some headers can't be set, and then I have to cut out the body of the response and write it to the OutputStream. But the body could be gzipped, or it could be an image, which I can't get to work yet. And some responses contain random characters everywhere, which looks like an encoding problem. It's a lot of trouble.

I'm getting a raw response because I'm using SOCKS to send an HTTP request. The program I'm working on is basically an HTTP proxy that can route requests through a SOCKS proxy, like Privoxy does.


Source: (StackOverflow)

Using a VPN to get a static IP on Heroku

I need to connect to an API with my Heroku/Rails app where I need to have a static IP.

I know about the add-on proximo - https://devcenter.heroku.com/articles/proximo - but it is insanely priced, so that's out of the question.

Most people in my situation ends up deploying to EC2 instead and using a an Elastic IP as their static IP. I've also tried this and it works, but I find the whole flow of playing around with EC2 really cumbersome.

I've read in some answers that it is possible to set up an EC2 server and use it as a proxy for your Heroku/Rails app - Heroku Static IP for SFTP - but it sounds very cryptic for a person who is not very server-savvy.

Can someone give a step-to-step tutorial on how to set up your Heroku/Rails app to use your EC2 instance as a proxy?


Source: (StackOverflow)

How to use Tor socks5 in R getURL

I want to use Tor in getURL function in R. Tor is working (checked in firefox), socks5 at port 9050. But when I set this in R, I get error

html <- getURL("http://www.google.com", followlocation = T, .encoding="UTF-8", .opts = list(proxy = "127.0.0.1:9050", timeout=15))
Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 
 '<html>\n<head>\n<title>Tor is not an HTTP Proxy</title>\n</head>\n<body>\n<h1>Tor is not an HTTP Proxy</h1>\n<p>\nIt appears you have configured your web browser to use Tor as an HTTP proxy.\nThis is not correct: Tor is a SOCKS proxy, not an HTTP proxy.\nPlease configure your client accordingly.

I've tried replace proxy with socks, socks5 but it didn't work.


Source: (StackOverflow)

How can I use a SOCKS 4/5 proxy with urllib2?

How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?


Source: (StackOverflow)