利用casperjs和tor來隱藏自己的ip地址
阿新 • • 發佈:2019-02-08
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
這樣就會看到此時顯示的地址和之前的地址不一樣了。