2020-02-17第15章、ssh

简单网络管理语言(Simple Network Management Language)是一种类自然语言的脚本语言,它采用snmp、telnet、ping、dns、arp、ssh、tcp、udp、web等协议访问网络设备,内置smtp协议用于告警等邮件的发送,支持excel、mysql、sqlite等3种方式进行网管数据的存取。

手册最新版:https://ladybirdsnml.github.io/snmlipv6utf8snmptelnetsshweb/snmldoc_utf8ipv6.html

第15章、ssh

  SSH 为 Secure Shell 的缩写,可以代替Telnet的安全协议。telnet是不安全的,在网络上用明文传送口令和数据,安全验证方式容易受到“中间人”(man-in-the-middle)的攻击。

1、ssh语句分析

ssh.connect ip {192.168.186.132} port {22} username {cisco} password {cisco}

登录远程设备,设备的IPV4地址为:192.168.186.132,服务端口号为:22,用户名“cisco”密码“cisco”

ssh.connect ip {FE80::1} port {22} username {cisco} password {cisco}

登录远程设备,设备的IPV6 地址为:[FE80::1],服务端口号为:22,用户名“cisco”密码“cisco”

ssh.set onrecv {-More-} send { %0a}

设置ssh自动输入选项,当接收到“-More-”时,自动发送一个空格和换行符

ssh.recv expect {Version}

接收服务器发送的文本,一直接收到指定字符串“Version”

ssh.recv for {3} seconds

接收3秒钟内服务器发送的文本,当服务器发送的文本中含有“-More-”时,自动发送一个空格和换行符

ssh.send {show version%0a}

发送字符串“show version”命令和换行键。

ssh.send text

发送选中的文本区域

ssh.close

关闭ssh连接。

2、示例脚本[C:\snmlipv6\ssh\ssh_ipv4.txt]

C:\snmlipv6\ssh\ssh_ipv4.txt

001screen.text at point {150} {30} string {15. ssh (ipv4) Test, (use ssh you need to get ssh.key License File)}

002var {v_y} value {60}

003screen.text at point {10} {~v_y~} string {No. server ip:port send command recv }

004

005screen.line from point {10} {75} to point {30} {75}

006screen.line from point {50} {75} to point {270} {75}

007screen.line from point {300} {75} to point {630} {75}

008

009screen.text at point {10} {425} string {1. run ssh_req.bat 2. send email with file ssh_req.txt%0d%0a}

010screen.text at point {10} {450} string {email1: [email protected], email2: [email protected]%0d%0a}

011

012var {v_time} value datetime

013var {v_i} value {0}

014run.set loglevel {debug}

015loop.begin

016  

017  var {v_i} add number {1}

018  var {v_y} add number {18}

019  

020  ssh.connect ip {192.168.186.132} port {22} username {cisco} password {cisco}

021  ssh.set onrecv {-More-} send { %0a}

022  ssh.recv for {3} seconds

023  ssh.send {show version%0a}

024  ssh.recv expect {Version}

025  ssh.recv for {3} seconds

026  ssh.close

027  text.headpointer move to head

028  text.tailpointer move to tail

029  text.save append to file {C:\snmlipv6\ssh\ssh_out_ipv4~v_i~.txt}

030  screen.text at point {10} {~v_y~} string {~v_i~}

031  screen.text at point {50} {~v_y~} string {192.168.186.132:22 send 'show version'}

032  screen.text at point {300} {~v_y~} string {ssh.recv : ~text.bytes~ Bytes }

033  text.delete from headpointer

034  

035  if.var {v_y} > {100}

036    loop.exit

037  if.end

038loop.end

039run.end

  脚本执行画面如下:

3、 示例脚本[C:\snmlipv6\ssh\sshreg_nms.txt]

C:\snmlipv6\ssh\sshreg_nms.txt

001screen.text at point {150} {30} string {15. ssh Test, Ssh needs a License. Please write email to get ssh.key file.}

002var {v_y} value {60}

003

004screen.line from point {10} {75} to point {630} {75}

005screen.line from point {10} {425} to point {630} {425}

006

007

008screen.text at point {10} {80} string {1. run ssh_req.bat 2. send email with file ssh_req.txt%0d%0a}

009screen.text at point {10} {100} string {email1: [email protected], email2: [email protected]%0d%0a}

010

011var {v_time} value datetime

012var {v_i} value {0}

013

014text.add {run.version=[~run.version~]%0d%0a}

015text.add {run.arg.1=[~run.arg.1~]%0d%0a}

016text.add {v_time=[~v_time~]%0d%0a}

017

018text.add {os.type=[~os.type~]%0d%0a}

019text.add {os.version=[~os.version~]%0d%0a}

020

021text.add {nic.ip=[~nic.ip~]%0d%0a}

022text.add {nic.description=[~nic.description~]%0d%0a}

023text.add {nic.mac=[~nic.mac~]%0d%0a}

024

025text.add {1. run ssh_req.bat 2. send email with file ssh_req.txt%0d%0a}

026text.add {email1: [email protected], email2: [email protected]%0d%0a}

027

028text.headpointer move to head

029text.tailpointer move to tail

030text.save append to file {C:\snmlipv6\ssh\ssh_req.txt}

031

032screen.text at point {120} {180} string { File C:\snmlipv6\ssh\ssh_req.txt created ok!, total ~text.bytes~ bytes.}

033run.end

  脚本执行画面如下:

4、示例脚本[C:\snmlipv6\ssh\ssh_ipv6.txt]

C:\snmlipv6\ssh\ssh_ipv6.txt

001screen.text at point {150} {30} string {15.3 ssh (ipv6) Test, (use ssh you need to get ssh.key License File)}

002var {v_y} value {60}

003screen.text at point {10} {~v_y~} string {No. server ip:port send command recv }

004

005screen.line from point {10} {75} to point {30} {75}

006screen.line from point {50} {75} to point {270} {75}

007screen.line from point {300} {75} to point {630} {75}

008

009screen.text at point {10} {425} string {1. run ssh_req.bat 2. send email with file ssh_req.txt%0d%0a}

010screen.text at point {10} {450} string {email1: [email protected], email2: [email protected]%0d%0a}

011

012var {v_time} value datetime

013var {v_i} value {0}

014run.set loglevel {debug}

015loop.begin

016  

017  var {v_i} add number {1}

018  var {v_y} add number {18}

019  

020  ssh.connect ip {FE80::1} port {22} username {cisco} password {cisco}

021  ssh.set onrecv {-More-} send { %0a}

022  ssh.recv for {3} seconds

023  ssh.send {show version%0a}

024  ssh.recv expect {Version}

025  ssh.recv for {3} seconds

026  ssh.close

027  text.headpointer move to head

028  text.tailpointer move to tail

029  text.save append to file {C:\snmlipv6\ssh\ssh_out_ipv4~v_i~.txt}

030  screen.text at point {10} {~v_y~} string {~v_i~}

031  screen.text at point {50} {~v_y~} string {[FE80::1]:22 send 'show version'}

032  screen.text at point {300} {~v_y~} string {ssh.recv : ~text.bytes~ Bytes }

033  text.delete from headpointer

034  

035  if.var {v_y} > {100}

036    loop.exit

037  if.end

038loop.end

039run.end

  脚本执行画面如下:

目录: 1、var 2、screen 3、snmp 4、telnet 5、text 6、if 7、loop 8、dns 9、ping 10、arp 11、excel 12、smtp 13、tcp 14、udp 15、ssh 16、web 17、mysql 18、sqlite 19、Run 20、sys 21、macro 附录1、全部语句

你可能感兴趣的:(2020-02-17第15章、ssh)