ssh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   | ssh支持正向代理、反向代理、socks代理
  正常cs模式下,cs端都开有22端口
  本地22->远程22
  正向代理 -L,本地代理远程端口 远程3306通过22将本地3306打开,监听本地3306
  反向代理 -R,远程代理本地端口 本地3306通过22将远程3306打开,监听远程3306
  socks代理 -D,为本机开启远程socks代理 -D更像是-L代理远程scoks的1080,不过不开远程1080 本地1080通过22打通远程socks,本地监听1080为socks代理 ssh -CNTfD 0.0.0.0:1080 root@远程ip -o TCPKeepAlive=yes ps:windows下openssh不太稳定,可以使用git windows自带的ssh
   | 
 
autossh.py windows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   | import psutil
  import time import os import sys
  def if_ssh():     flag = False     for i in psutil.process_iter(['name', 'cmdline']):         if i.name() == 'ssh.exe':             flag = True             break     return flag
 
  def main(sh, stime):     while 1:         if if_ssh():             time.sleep(int(stime))         else:             os.system(sh)
 
  if __name__ == '__main__':     if len(sys.argv) == 1:         print('autossh command stime')     else:         sh = sys.argv[1]         if len(sys.argv) > 2:             stime = sys.argv[2]         else:             stime = 5         main(sh, stime)
   | 
 
start.vbs
使用pyinstaller 将autossh.py打包成autossh.exe,然后将远程ip的ssh设置成本地免密登陆
start.vbs可以将autossh.exe开在windows后台,chrome使用SwitchyOmega或Proxy SwitchyOmega代理本地1080端口
1 2 3
   | dim WSHshellA set WSHshellA = wscript.createobject("wscript.shell") WSHshellA.run "autossh.exe "&chr(34)&"ssh.exe -CNTfD 0.0.0.0:1080 root@远程ip -o TCPKeepAlive=yes"&chr(34)&" 10",0 ,true
   | 
 
参考
使用ssh正向连接、反向连接、做socks代理的方法