简单网络管理语言(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
第9章、ping
“ping”这个名字源于声纳定位操作。目的是为了测试另一台主机、网络设备是否可达。ping是一个通信协议,是TCP/IP协议的一部分;ping也是Windows、Unix和Linux系统下的一个命令, ping命令可检查网络是否连通,分析和判定网络故障。
1、ping语句分析
ping.ip {220.181.12.207} ttl {64} size {32}
ping测试,主机、设备ip为220.181.12.207,发送报文的ttl值为64,发送报文的长度为32字节
ping语句执行后,系统创建、更新以下变量,示例值如下:
ping.dest_ip=[220.181.12.207],目的IP
ping.received_responses=[1],接收到响应报文的个数
ping.roundtrip_time_milliseconds=[56],响应时间(毫秒)
ping.reply_ip=[220.181.12.207],应答报文的IP,当ttl减小到0的时候,网络设备应答
ping.reply_ttl=[54],应答报文的ttl
ping.reply_bytes=[32],应答报文的长度
ping.status=[IP_SUCCESS]
ping语句执行后,通过检查变量“ping.status”是否为“IP_SUCCESS”来判断ping是否成功。
2、示例脚本[C:\snmlipv6\ping\ping_ipv4.txt]
C:\snmlipv6\ping\ping_ipv4.txt
001screen.text at point {150} {30} string {9.ping test (ipv4): ttl,size,roundtrip_time,ip}
002
003var {v_ttl} value {0}
004var {v_y} value {60}
005screen.text at point {50} {~v_y~} string {send ping request}
006screen.line from point {10} {75} to point {180} {75}
007screen.text at point {350} {~v_y~} string {ping response}
008screen.line from point {200} {75} to point {630} {75}
009
010var {v_y} value {80}
011screen.text at point {10} {~v_y~} string {Dest IP Addr}
012screen.text at point {110} {~v_y~} string {TTL}
013screen.text at point {150} {~v_y~} string {Bytes}
014
015screen.text at point {200} {~v_y~} string {IP Addr}
016screen.text at point {300} {~v_y~} string {TTL}
017screen.text at point {350} {~v_y~} string {Bytes}
018screen.text at point {400} {~v_y~} string {ms}
019screen.text at point {450} {~v_y~} string {ping.status}
020
021run.set loglevel {debug}
022dns.get var {ip_addr} host {mail.163.com}
023run.set loglevel {nolog}
024
025var {v_ttl} value {0}
026var {v_y} value {80}
027var {v_sendbytes} value {1000}
028loop.begin
029 var {v_ttl} add number {1}
030 var {v_y} add number {20}
031 run.set loglevel {debug}
032 ping.ip {~ip_addr~} ttl {~v_ttl~} size {~v_sendbytes~}
033 run.set loglevel {nolog}
034 screen.text at point {10} {~v_y~} string {~ping.dest_ip~}
035 screen.text at point {110} {~v_y~} string {~v_ttl~}
036 screen.text at point {150} {~v_y~} string {~v_sendbytes~}
037
038 screen.text at point {200} {~v_y~} string {~ping.reply_ip~}
039 screen.text at point {300} {~v_y~} string {~ping.reply_ttl~}
040 screen.text at point {350} {~v_y~} string {~ping.reply_bytes~}
041 screen.text at point {400} {~v_y~} string {~ping.roundtrip_time_milliseconds~}
042 screen.text at point {450} {~v_y~} string {~ping.status~}
043 if.var {v_ttl} > {16}
044 loop.exit
045 if.end
046loop.end
047
048run.end
脚本执行画面如下:
3、示例脚本[C:\snmlipv6\ping\ping_ipv6.txt]
C:\snmlipv6\ping\ping_ipv6.txt
001screen.text at point {150} {30} string {9.ping test (ipv6): ttl,size,roundtrip_time,ip}
002
003var {v_ttl} value {0}
004var {v_y} value {60}
005screen.text at point {50} {~v_y~} string {send ping request}
006screen.line from point {10} {75} to point {180} {75}
007screen.text at point {350} {~v_y~} string {ping response}
008screen.line from point {200} {75} to point {630} {75}
009
010var {v_y} value {80}
011screen.text at point {10} {~v_y~} string {Dest IP Addr}
012screen.text at point {110} {~v_y~} string {TTL}
013screen.text at point {150} {~v_y~} string {Bytes}
014
015screen.text at point {200} {~v_y~} string {IP Addr}
016screen.text at point {400} {~v_y~} string {ms}
017screen.text at point {450} {~v_y~} string {ping.status}
018
019#run.set loglevel {debug}
020dns.set ipmode {ipv6}
021#dns.get var {ip_addr} host {www.ipv6-test.com}
022
023var {ip_addr} value {FE80::1}
024
025var {v_ttl} value {0}
026var {v_y} value {80}
027var {v_sendbytes} value {1000}
028loop.begin
029 var {v_ttl} add number {1}
030 var {v_y} add number {20}
031 ping.ip {~ip_addr~} ttl {~v_ttl~} size {~v_sendbytes~}
032
033 screen.text at point {10} {~v_y~} string {~ping.dest_ip~}
034 screen.text at point {110} {~v_y~} string {~v_ttl~}
035 screen.text at point {150} {~v_y~} string {~v_sendbytes~}
036 screen.text at point {200} {~v_y~} string {~ping.reply_ip~}
037 screen.text at point {400} {~v_y~} string {~ping.roundtrip_time_milliseconds~}
038 screen.text at point {450} {~v_y~} string {~ping.status~}
039 if.var {v_ttl} > {16}
040 loop.exit
041 if.end
042loop.end
043
044run.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、全部语句