Posts Tagged: gwibber


9
Jul 09

用 tsocks 和 proxychains 使 Linux 下所有软件能够翻墙

情况
由于最近在中国某个地方爆发了 riot, 所以境内很多网站又是无法访问 (twitter.com、facebook.com 等),让我们这些网民很无奈。

使用 SSH 翻墙
我曾经介绍过如何使用 SSH 来建立一个 SOCKS 代理服务器,让你能够在 Firefox 里正常访问以上所提起的网址。然而不是所有 Linux 软件都能支持代理服务器。如果你最热爱的 Linux 工具需要访问”被封”的网站,又没有嵌入的代理支持,该怎么办呢?
遇到这种情况当然不要放弃该软件… 毕竟我们用的系统是 Linux 而不是以前让我们咳声叹气,丧失信心的 Windows,总有一个方法去解决问题。

举个例子吧
我不久前发现了 Twitter 这个网站。我一开始不经常用,也搞不明白别人为什么对这个 web 2.0 服务都着了迷。后来我在推特上跟的人越来越多,跟着我的人亦是日益增多,不知不觉我也迷上了该网站,天天都会上。凡是经常用推特的人一般都会用一个推特的客户端,这才能跟得上朋友们的状态更新和最火热的网络新闻。本人作为 Ubuntu 的用户,我自然就选了 Gwibber 这个基于 GNOME 的客户端来访问我的推特。这个软件功能很丰富,用起来得心应手,不过总有一个问题让我有点遗憾,就是 Gwibber 还不听从 GNOME 的代理设置。平时这也不是一个很大的问题,但是每遇中国网络封锁较严重时,都会让我暂时无法使用该软件。

解决方案… Tsocks
经过几个 Google 搜索,我最终很高兴地发现 Linux 有一个能够强迫任何软件通过 SOCKS 代理上网的工具,其名就是 tsocks。Tsocks 是一个透明 SOCKS 代理软件,只要你电脑有一个连接到国外服务器的 SSH 隧道,你就能让任何软件翻墙。

安装并配置 Tsocks
以下说明都是为了那些使用 Ubuntu 的 Linux 用户,不过在别的 Linux 发行版下,安装的过程应该与此差不多。

在终端中:

sudo apt-get install tsocks

修改配置文件:

sudo nano /etc/tsocks.conf

将其内容改成以下几行并保存退出:

local = 192.168.1.0/255.255.255.0 #local表示本地的网络,也就是不使用socks代理的网络
server = 127.0.0.1 # SOCKS 服务器的 IP
server_type = 5 # SOCKS 服务版本
server_port = 9999 #SOCKS 服务使用的端口

你可能需要修改一下以上内容,用你自己的 SSH 隧道设置。

运行软件
用 tsocks 运行你的软件很简单,在终端中:

tsocks 你的软件 &

我现在运行 Gwibber 都是这样运行的:

tsocks gwibber &

祝你们翻墙愉快!

EDIT—————–>

我今天还发现了另外一个工具,其功能似乎比 tsocks 要更丰富,配置起来更简单,而且不会那么容易出错。这个工具就是 proxychains。以下有配置方法:

sudo apt-get install proxychains

修改配置文件 (/etc/proxychains.conf),应该如下:

# proxychains.conf  VER 2.0
#
#        HTTP, SOCKS4, SOCKS5 tunneling proxifier.
#

# The option below identifies how the ProxyList is treated.
# only one option should be uncommented at time,
# otherwise the last appearing option will be accepted
#
# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app
#
# Strict - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# all proxies must be online to play in chain
# otherwise EINTR is returned to the app
#
# Random - Each connection will be done via random proxy
# (or proxy chain, see  chain_len) from the list
# this option is good for scans

dynamic_chain
#strict_chain
#random_chain

# Make sense only if random_chain
chain_len = 2

# Quiet mode (no output)
#quiet_mode

# Write stats about good proxies to proxychains.stats
#write_stats

#Some timeouts in milliseconds
#
tcp_read_time_out 15000
tcp_connect_time_out 10000

[ProxyList]
# ProxyList format
#       type  host  port [user pass]
#       (values separated by 'tab' or 'blank')
#
#
#        Examples:
#
#            	socks5	192.168.67.78	1080	lamer  secret
#		http	192.168.89.3	8080	justu	hidden
#	 	socks4	192.168.1.49	1080
#	        http	192.168.39.93	8080
#
#
#       proxy types: http, socks4, socks5
#        ( auth types supported: "basic"-http  "user/pass"-socks )
#
#http 	10.0.0.5 3128
socks5 127.0.0.1 9999
socks4 127.0.0.1 9050

注意事项:

  1. 要选 dynamic_chain 而不是 random_chain
  2. 可以列举几个代理服务器,proxychains 会按顺序用,代理无法访问即自动选用下一个
  3. 代理服务器要根据自己电脑的情况自行调整

运行 proxychains
运行 proxychains 跟运行 tsocks 完全一样。在终端中:

proxychains 你的软件 &

比如说:

proxychains chromium-browser &

我还是推荐你使用 proxychains!


30
May 09

Gwibber Error 400 No Twitter Updates

After recently updating Gwibber to the latest daily version, I noticed that I was regularly getting the below error and that nothing was showing up in my Twitter timeline:

HTTPError: HTTP Error 400: Bad Request

The Traceback is as below:

Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/gwibber/microblog/__init__.py", line 50, in get_data
    for message in method(client):
  File "/usr/lib/python2.6/dist-packages/gwibber/microblog/twitter.py", line 207, in responses
    for data in self.get_direct_messages():
  File "/usr/lib/python2.6/dist-packages/gwibber/microblog/twitter.py", line 182, in get_direct_messages
    "https://twitter.com/direct_messages.json"))
  File "/usr/lib/python2.6/dist-packages/gwibber/microblog/twitter.py", line 158, in connect
    url, data, headers = {"Authorization": self.get_auth()})).read()
  File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.6/urllib2.py", line 389, in open
    response = meth(req, response)
  File "/usr/lib/python2.6/urllib2.py", line 502, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.6/urllib2.py", line 427, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.6/urllib2.py", line 361, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 510, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request

At first I thought that this was a problem with Gwibber, however, after a bit of research, it turns out that this is a problem at Twitters end. Basically, Twitter recently changed their API and now limits the number of update requests you can make per hour using Gwibber. If you have your Gwibber client set to update too regularly (i.e. every minute or so) then it will run out of update permissions before the hour is over and you will get lots of error messages. It is therefore recommended to set the update frequency to something a bit higher (5 minutes should be fine) and hopefully you shouldn’t see the error any more.

If you want to know how many more Twitter update requests you have remaining (for the current hour), there is a simple curl command that you can enter in a terminal that will prompt you for a password and then provide the info you need.

$ user@jonoxps:~$ curl -u yourusernamehere http://twitter.com/account/rate_limit_status.json
$ Enter host password for user 'yourusernamehere':
$ {"reset_time_in_seconds":1243702342,"remaining_hits":0,"hourly_limit":100,"reset_time":"Sat May 30 16:52:22 +0000 2009"}

Sure enough, as soon as the clock turned 16:52:22, my hourly_limit went back up to 100 and Gwibber started working again!

Hopefully that should clear things up for a few of you, there is more information about the bug on Launchpad.