1, 首先在ubuntu上面安装tor
详情可以参考 https://www.torproject.org/docs/debian.html.en
You need to add the following entry in /etc/apt/sources.list
or a new file in /etc/apt/sources.list.d/
:
deb http://deb.torproject.org/torproject.org trusty main deb-src http://deb.torproject.org/torproject.org trusty main
Then add the gpg key used to sign the packages by running the following commands at your command prompt:
gpg --keyserver keys.gnupg.net --recv 886DDD89 gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
You can install it with the following commands:
$ apt-get update
$ apt-get install tor deb.torproject.org-keyring
2, 利用casperjs访问网站 https://whatismyipaddress.com/ 来测试自己现在的对外IP
创建一个js文件,名为index.js。内容如下。
var document = [];
var casper = require('casper').create({
verbose: false,
logLevel: "info"
});
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
casper.start("https://whatismyipaddress.com/", function() {
this.evaluate(function () {
console.log('hello world');
console.log('current ip is: '+document.querySelector('a[href^="//whatismyipaddress.com/ip/"]').textContent.trim());
});
});
casper.run();
3, 然后通过如下命令来执行
$ casperjs index.js
这是可以看到自己的ip地址。
4, 利用tor的代理来执行casperjs的脚本,如下
$ casperjs –proxy=127.0.0.1:9050 –proxy-type=socks5 index.js
这样就会看到此时显示的地址和之前的地址不一样了。