1. 程式人生 > >自己主動化腳本ssh以及telnet發送命令並退出(windows和linux都適用)

自己主動化腳本ssh以及telnet發送命令並退出(windows和linux都適用)

version 代理 sta agen apply raw .net tun for

須要安裝putty,用到的命令是plink: [html] view plaincopy
  1. PuTTY Link: command-line connection utility
  2. Unidentified build, Jun 23 2015 11:43:58
  3. Usage: plink [options] [user@]host [command]
  4. ("host" can also be a PuTTY saved session name)
  5. Options:
  6. -V print version information and exit
  7. -pgpfp print PGP key fingerprints and exit
  8. -v show verbose messages
  9. -load sessname Load settings from saved session
  10. -ssh -telnet -rlogin -raw -serial
  11. force use of a particular protocol
  12. -P port connect to specified port
  13. -l user connect with specified username
  14. -batch disable all interactive prompts
  15. The following options only apply to SSH connections:
  16. -pw passw login with specified password
  17. -D [listen-IP:]listen-port
  18. Dynamic SOCKS-based port forwarding
  19. -L [listen-IP:]listen-port:host:port
  20. Forward local port to remote address
  21. -R [listen-IP:]listen-port:host:port
  22. Forward remote port to local address
  23. -X -x enable / disable X11 forwarding
  24. -A -a enable / disable agent forwarding
  25. -t -T enable / disable pty allocation
  26. -1 -2 force use of particular protocol version
  27. -4 -6 force use of IPv4 or IPv6
  28. -C enable compression
  29. -i key private key file for authentication
  30. -noagent disable use of Pageant
  31. -agent enable use of Pageant
  32. -m file read remote command(s) from file
  33. -s remote command is an SSH subsystem (SSH-2 only)
  34. -N don‘t start a shell/command (SSH-2 only)
  35. -nc host:port
  36. open tunnel in place of session (SSH-2 only)
  37. -sercfg configuration-string (e.g. 19200,8,n,1,X)
  38. Specify the serial configuration (serial only)

本來一直用plink做隧道代理FQ用。閑來無聊看了看幫助,不看不知道。一看嚇一跳 順利的攻克了曾經沒有實現的功能,特來記錄
有用場景1產品發給用戶以後發現有bug。可是安裝的位置僅僅能遠程,並且數量非常多,這個時候須要對產品升級怎麽辦,不可能一個個ssh,或者網頁配置吧,那麽自己主動化ssh發送命令就派上用途了,一個腳本循環ssh。wget固件並並升級一氣呵成。之前公司就遇到過
有用場景2如今有1000塊板子出貨要貼標簽,而之前MAC地址由於某種原因沒記錄。這個時候怎麽辦,也不可能一個個去登陸復制粘貼。再保存到打印機吧,一個腳本打印出來,就是這麽任性
ssh登陸執行ls命令 echo y| plink -ssh [email protected] -pw password ls
ssh登陸依次運行command.txt的命令: echo y| plink -ssh [email protected] -pw password -m command.txt
telnet登陸執行ifconfig並退出: ?echo ‘ifconfig ;exit‘| plink -telnet 192.168.1.1 另外還有 -ssh -telnet -rlogin -raw -serial

基於這幾個核心命令,能夠盡情發揮了
學無止境

測試發現ssh 最多傳入 1024個字符

自己主動化腳本ssh以及telnet發送命令並退出(windows和linux都適用)