• 自己主动化脚本ssh以及telnet发送命令并退出(windows和linux都适用)


    须要安装putty,用到的命令是plink:
    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做隧道代理翻墙用。闲来无聊看了看帮助,不看不知道。一看吓一跳
    顺利的攻克了曾经没有实现的功能,特来记录

    有用场景1产品发给用户以后发现有bug。可是安装的位置仅仅能远程,并且数量非常多,这个时候须要对产品升级怎么办,不可能一个个ssh,或者网页配置吧,那么自己主动化ssh发送命令就派上用途了,一个脚本循环ssh。wget固件并并升级一气呵成。之前公司就遇到过

    有用场景2如今有1000块板子出货要贴标签,而之前MAC地址由于某种原因没记录。这个时候怎么办,也不可能一个个去登陆复制粘贴。再保存到打印机吧,一个脚本打印出来,就是这么任性

    ssh登陆执行ls命令
    echo yplink -ssh root@192.168.1.1 -pw password ls

    ssh登陆依次运行command.txt的命令:
    echo y| plink -ssh root@192.168.1.1 -pw password -m command.txt

    telnet登陆执行ifconfig并退出:
    echo 'ifconfig ;exit'| plink -telnet 192.168.1.1
     
    另外还有   -ssh -telnet -rlogin -raw -serial

    基于这几个核心命令,能够尽情发挥了

    学无止境

    測试发现ssh 最多传入  1024个字符
  • 相关阅读:
    记录两种获取配置文件的方法
    jsp-自定义标签
    转载 -jsp静态包含和动态包含的区别
    Linux基础知识笔记
    关于HTTP协议
    关于orcale创建type的一些小经验(遇到的坑)
    servlet处理乱码之post和get
    发布restful类型的接口
    ros2 dashing 安装失败指南
    exit回调
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6985601.html
Copyright © 2020-2023  润新知