USAssh.com 最早成立于2009年,是一家注重用户体验、高速稳定、诚信专业、老牌资深的美国SSH代理服务提供商,专注于给用户提供优质稳定的SSH代理和VPN代理服务。
2012-7-23 update:更新ruby获取密码脚本!
最近发现usassh提供的有免费测试,美中不足的是每整点更换密码。经过摸索自己写了个脚本实现自动抓取密码并自动重新连接。(如果您觉得服务不错,请购买付费账户,也算支持别人的工作 🙂 )
脚本使用了工具expect,Ubuntu用户可以用sudo apt-get install expect安装。
1.expect脚本内容如下,主要实现自动登录的处理。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#! /usr/bin/expect # # sshlogin by yemingtu set timeout -1 # 从参数中获取用户名和密码 set login_name [lindex $argv 0] set login_pass [lindex $argv 1] # 免费SSH服务器 set ssh_server "free.usassh.com" # 新建进程ssh隧道开启9000端口用于动态转发,-o StrictHostKeyChecking=no参数略过缓存key提示 spawn ssh -D 9000 -g -N -p 80 -C -o StrictHostKeyChecking=no $login_name@$ssh_server # 自动输入密码 expect "*password*" send "$login_pass\r" # 密码错误退出脚本 expect "*again*" exit 0 interact |
2.启动SSH状态检测脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#! /bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin # php写的抓密码页面,返回最新密码 url="http://hmmabc.com/ssh.php" # 检测ssh进程是否存在,如果存在则退出 if [ -n "$(ps aux|grep "ssh -D 9000"|grep -v grep)" ] then exit 0 fi password=`curl $url` # 检测获取的密码是否为空 if [ -z "$password" ] then exit 0 fi # 调用上面的expect脚本登录 /usr/bin/expect /home/yourname/ssh/sshlogin usassh $password |
3.将上面两个脚本保存到文件,比如/home/yourname/ssh目录,并用chmod +x * 加上可执行权限。
4.用crontab -e命令编辑cron任务,每分钟执行一次autossh脚本
0-59 * * * * /home/yourname/ssh/autossh &
最后附上自己写的php抓取密码脚本,非常简单,仅供参考~ 🙂
1 2 3 4 5 6 7 8 9 10 |
<?php $url = "http://www.usassh.com/free.php"; $contents = file_get_contents($url); preg_match_all ("#<td>(.*?)</td>#",$contents,$matches); foreach ($matches[1] as $key => $value) { if(strlen($value) == 5){ echo $value; } } ?> |
ruby获取密码脚本:(需要nokogiri)
1 2 3 4 5 6 7 8 9 10 11 |
require 'nokogiri' require 'open-uri' uri = 'http://www.usassh.com/free.php' doc = Nokogiri::HTML(open(uri)) doc.css('strong font').each do |link| if(link.content.length == 5) puts link.content end end |
推荐一个多线程的ssh代理,迅雷般的速度,http://www.myssh.org