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: ladybird_snml@protonmail.com, email2: ladybird_snml@hotmail.com%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: ladybird_snml@protonmail.com, email2: ladybird_snml@hotmail.com%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: ladybird_snml@protonmail.com, email2: ladybird_snml@hotmail.com%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: ladybird_snml@protonmail.com, email2: ladybird_snml@hotmail.com%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、全部语句

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,122评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,070评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,491评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,636评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,676评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,541评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,292评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,211评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,655评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,846评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,965评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,684评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,295评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,894评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,012评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,126评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,914评论 2 355

推荐阅读更多精彩内容