确保 torrent 客户端使用 openvpn

确保 torrent 客户端使用 openvpn

我最近注册了 VPN 提供商并登录,我使用网络管理器进行正常的无线连接,然后从网络管理器启动 openvpn 连接。在我的浏览器中,我可以通过访问 IP 位置查找器站点来检查我是否正在使用隧道,但如何确保我的 torrent 客户端实际使用此连接?例如,我的 VPN 提供商是否会在一段时间后(有意或无意)将我注销,然后我的 torrent 客户端开始使用仍然可用的正常 WiFi 连接?

答案1

如何确保我的 torrent 客户端确实使用此连接?

有一个网站,检查我的TorrentIP,正是这样做的。基本上,您下载专门为您生成的 torrent 文件,一旦您在客户端中打开它,它就会报告正在使用的 IP 地址。 IP 应直接显示在您的客户端中,但您也可以重新访问也会显示该 IP 的站点。该网站上有一个常见问题解答,您可以在其中获取更多信息。

难道我的 VPN 提供商会在一段时间后(有意或无意)将我注销,然后我的 torrent 客户端开始使用仍然可用的正常 WiFi 连接吗?

绝对地。常见问题解答检查我的TorrentIP这篇文章来自 TorrentFreak解释一些防止这种情况发生的选项,其中包括使用特定的防火墙规则,更改 TCP/IP 路由,或使用具体的 应用

如果你碰巧使用激流你可以将它绑定到一个特定的 IP 地址(VPN 给你的地址),如果你失去了与该接口的连接,rtorrent 将停止下载/播种(说实话,我不是 100% 这个说法是正确的,但确实如此)至少有一些有趣的东西值得研究)。如果您的 VPN IP 是 0.0.0.0,则只需将其添加到您的.rtorrent.rc

bind = 0.0.0.0

答案2

运行命令sudo ifconfig。它应该返回一个连接列表,其中一个类似于tun0您的 VPN 隧道。在tun0块中,将会有一个inet addr xxx.xxx.xxx.xxx.

获取inet addr并添加它或编辑您的.rtorrent.rc文件(可能位于您的/home目录中),使其内容如下:

bind = xxx.xxx.xxx.xxx

(显然你会填写数字,而不是xxx.xxx.xxx.xxx)。

每次连接时都这样做很乏味,但是如果您的 VPN 超时并且您在 rtorrent 仍在运行时被踢到您的真实 IP,则揭露您的实际 IP 是一个真正的问题。

我正在编写一个脚本,以便在每次启动时自动执行此操作。如果它有效,我会尝试回来并发布它。

正如这里所承诺的,这是一个为您执行此操作的脚本。除非您在启动时启动 VPN,否则在启动时运行它是不切实际的,因此您应该以 root 身份手动运行它,或者在启动 VPN 之后和启动 rtorrent 之前从 .rtorrent.rc 所在的目录中使用 sudo 运行它。

很抱歉发布需要 root 权限的内容,切勿从论坛运行任何要求 root 权限的内容,除非您自己检查以确保安全。

脚本将解析 ifconfig 输出,查找与字符串“tun”关联的 IP 地址,并将其作为绑定语句写入 .rtorrent.rc 文件的最后一行。

同时,它首先创建一个名为 .svrtvpn 的目录,在其中存储现有 .rtorrent.rc 文件的最多十个备份,然后从 .rtorrent.rc 文件中删除所有其他绑定语句,然后写入检测到的要绑定的 VPN IP 地址作为.rtorrent.rc 文件中的最后一行

我超级懒,所以花时间编写脚本并快速调用它比每次运行 VPN 时额外花 10 秒手动检测和编写绑定要容易得多。 #!/bin/bash

#svrtvpn.sh ver 0.3  "shadowvision rtorrent vpn" 01-05-2016 @ shadowvision.com/org
#a simple script to set your .rtorrent.rc bind to the ip address your vpn is using so that if your vpn gets disconnected, rtorrent will stop and you wont be unmasked
#WARNING WARNING WARNING WARNING under some circumstances it erases parts or even the entire .rtorrent file, but it makes a backup first so namaste :)
#this seems to happen if there arent any bind addresses to start with so the script will append a bogus one before it does anything else.

#syntax before starting rtorrent, run as root from the directory where your .rtorrent.rc is, follow the prompt and enter your linux user name that you will be running rtorrent as.

#provide help
if [ "$1" = "help" ]; then
echo "  use: before starting rtorrent, run as root from the directory where your .rtorrent.rc is."
echo "  script is dependent on ifconfig returning the vpn connection as 'tun'.  if that isnt what your connection is called you will have to manually change it inside the script"
echo "  svrtvpn.sh saves your existing .rtorrent.rc file in a directory called .svrtvpn with the extension of the epoch time in seconds. the last ten backups are saved."
echo "  if you use this script, the bind = address will always be the last line of your .rtorrent.rc file"
echo "  svrtvpn.sh ver 0.3  "shadowvision rtorrent vpn" 01-05-2016 @ shadowvision.com/org"
echo "  a simple script to set your .rtorrent.rc bind to the ip address your vpn is using so that if your vpn gets disconnected, rtorrent will stop and you wont be unmasked"
echo "  shadowvision makes no claims as to the usability of this script on your system, it was tested on kali linux with network manager and PIA 'private internet access'"
exit
fi

#first check to see if you have a .rtorrent.rc file.  if you dont it tells you so and exits.
RTORRENTFILE=./.rtorrent.rc
if [ ! -f "$RTORRENTFILE" ]; then
    echo "You dont have  .rtorrent.rc in this directory, script will now exit!"
    exit
fi

# set your backup directory variable
SVDIR=.svrtvpn

#tell the user its using a backup directory
if [ -d "$SVDIR" ]; then
  echo "using existing $SVDIR directory for backups.  your your last ten backups will be saved here."


#now make your .svrtvpn directory where your backups are stored if it doesnt already exist
else
mkdir -p $SVDIR
echo "created a directory called $SVDIR, your last ten .rtorrent.rc backups are stored here."
fi


#first find out what user you are running as, the script sets the ownership of .rtorrent.rc to this user at the end

SVUSER=$(ls -ld .rtorrent.rc | awk '{print $3}')
echo "your .rtorrent.rc file is owned by $SVUSER , it should remain read/write by that user and read for everyone else at the end of this script."
#copy your .rtorrent.rc to a backup file with the seconds of epoch time as the extension.
cp .rtorrent.rc ./$SVDIR/.rtorrent.rc.$(date +"%s")

#append a bogus ip bind so that the script wont erase your entire file
echo "bind = 999.999.999.999" >> .rtorrent.rc


#find out what your current vpn ip is, and if you dont have one, exit. as long as you didnt previously have a valid ip entered rtorrent wont start.
if $( ifconfig |grep -q -A1 tun); then
VPNIP=$(ifconfig |grep -A1 tun |grep inet | grep  -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)

#find any bind addresses in the file so we can delete them
DELINE=$(cat .rtorrent.rc |grep   bind | grep  '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | grep -v \# |grep -v \:)

#delete old bind addresses by tediously copying everything but found addresses to a temp file then back to the original file.
cat .rtorrent.rc |grep -v "$DELINE" > ./$SVDIR/.rtorrent.xx
cat ./$SVDIR/.rtorrent.xx > .rtorrent.rc

#add the vpn ip to the end of your file
echo "bind =" "$VPNIP" >> .rtorrent.rc

#make sure ownerships and read perms are sane
chown $SVUSER .rtorrent.rc
chmod u+rw .rtorrent.rc
chmod a+r .rtorrent.rc
chown -R $SVUSER $SVDIR
chmod -R a+r $SVDIR

#only save last ten backups, note the number is set to 13 because the three files . .. and .xx file arent backups
cd $SVDIR

ls -tra | head -n -13 | xargs --no-run-if-empty rm

cd -
else

#if you got to here it didnt work so set a bogus bind address so rtorrent wont start
VPNIP=999.999.999.999

#just like above find any old bind addresses so we can remove them
DELINE=$(cat .rtorrent.rc |grep   bind | grep  '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | grep -v \# |grep -v \:)
cat .rtorrent.rc |grep -v "$DELINE" > ./$SVDIR/.rtorrent.xx
cat ./$SVDIR/.rtorrent.xx > .rtorrent.rc

#set the bogus address
echo "bind =" "$VPNIP" >> .rtorrent.rc

#reset sane perms
chown $SVUSER .rtorrent.rc
chmod u+rw .rtorrent.rc
chmod a+r .rtorrent.rc
chown -R $SVUSER $SVDIR
chmod -R a+r $SVDIR

#tell us what happened
echo "you are not connected to a vpn, this wont work"
echo "your bind address has been set to 999.999.999.999"
fi

相关内容