自己搭建自动化巡检系统(三) 通过telnet实现远程创建loopback
2017-08-28 19:43
253 查看
我们在上一章完成了用代码操作telnet,实现了远程控制,分析前面的代码会发现健壮性太低,需要进行优化,后续会通过开发一个交互式界面来完成人工介入操作网络的过程。本次实验目的:实现自动化创建环回口
首先更新拓扑,拉出新的路由器和一台交换机
import telnetlib
import time
def main():
Host="192.168.10.100"
username="yerik"
password="1111"
commends=['enable','2222','conf t']#相关指令
tn = telnetlib.Telnet(Host,port=23,timeout=10)
tn.set_debuglevel(2)
# login input username
tn.read_until('Username: ') # 期待回复
tn.write(username+'\n')
# input password
tn.read_until('Password: ') # 期待回复
tn.write(password+'\n')
tn.read_until('R1>')
for commend in commends:
tn.write("%s\n" % commend)
'''
tn.read_until('R1#')
tn.write('configure')
time.sleep(1)
tn.write('t')'''
tn.read_until('R1(config)#')
loopback = 'int lo'
ipaddr = ' 255.255.255.255'
exit = 'exit'
for i in range(1,5):
loopbackn=loopback+str(i)
time.sleep(1)
tn.write("%s\n" % loopbackn)
ipaddrn='ip add '+str(i)+'.'+str(i)+'.'+str(i)+'.'+str(i)+ipaddr
time.sleep(1)
tn.write("%s\n" % ipaddrn)
time.sleep(1)
tn.write("%s\n" % exit)
tn.close()
if __name__=='__main__':
main()
发现已经创建成功了
由于此时还没有运行路由协议,请问有什么办法可以ping到这些环回口?使用ping中的严格源站路由技术,通过R2pingR1 在特权界面中,输入ping
ping
Protocol [ip]:
Target IP address: 2.2.2.2
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands
: y
Source address or interface: 192.168.10.102
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:Strict
Source route: 192.168.10.101
Loose, Strict, Record, Timestamp,Verbose[SV]:
Sweep range of sizes
:
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2,timeout is 2 seconds:
Packet sent with a source address of192.168.10.102
Packet has IP options: Total option bytes= 7, padded length=8
Strict source route: <*>
(192.168.10.101)
Reply to request 0 (20 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 1 (28 ms). Received packet has options
Total option bytes= 8, padded length=
99de
8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 2 (24 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 3 (16 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
End oflist
Reply to request 4 (28 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Success rate is 100 percent (5/5),round-trip min/avg/max = 16/23/28 ms
现实可以ping通
首先更新拓扑,拉出新的路由器和一台交换机
import telnetlib
import time
def main():
Host="192.168.10.100"
username="yerik"
password="1111"
commends=['enable','2222','conf t']#相关指令
tn = telnetlib.Telnet(Host,port=23,timeout=10)
tn.set_debuglevel(2)
# login input username
tn.read_until('Username: ') # 期待回复
tn.write(username+'\n')
# input password
tn.read_until('Password: ') # 期待回复
tn.write(password+'\n')
tn.read_until('R1>')
for commend in commends:
tn.write("%s\n" % commend)
'''
tn.read_until('R1#')
tn.write('configure')
time.sleep(1)
tn.write('t')'''
tn.read_until('R1(config)#')
loopback = 'int lo'
ipaddr = ' 255.255.255.255'
exit = 'exit'
for i in range(1,5):
loopbackn=loopback+str(i)
time.sleep(1)
tn.write("%s\n" % loopbackn)
ipaddrn='ip add '+str(i)+'.'+str(i)+'.'+str(i)+'.'+str(i)+ipaddr
time.sleep(1)
tn.write("%s\n" % ipaddrn)
time.sleep(1)
tn.write("%s\n" % exit)
tn.close()
if __name__=='__main__':
main()
发现已经创建成功了
由于此时还没有运行路由协议,请问有什么办法可以ping到这些环回口?使用ping中的严格源站路由技术,通过R2pingR1 在特权界面中,输入ping
ping
Protocol [ip]:
Target IP address: 2.2.2.2
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands
: y
Source address or interface: 192.168.10.102
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:Strict
Source route: 192.168.10.101
Loose, Strict, Record, Timestamp,Verbose[SV]:
Sweep range of sizes
:
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2,timeout is 2 seconds:
Packet sent with a source address of192.168.10.102
Packet has IP options: Total option bytes= 7, padded length=8
Strict source route: <*>
(192.168.10.101)
Reply to request 0 (20 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 1 (28 ms). Received packet has options
Total option bytes= 8, padded length=
99de
8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 2 (24 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Reply to request 3 (16 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
End oflist
Reply to request 4 (28 ms). Received packet has options
Total option bytes= 8, padded length=8
Strict source route:
(192.168.10.101)
<*>
Endof list
Success rate is 100 percent (5/5),round-trip min/avg/max = 16/23/28 ms
现实可以ping通
相关文章推荐
- 自己搭建自动化巡检系统(三) 通过telnet实现远程创建loopback
- 自己搭建自动化巡检系统(二) telnet远程登录
- 实现Windows远程连接Linux系统通过telnet连接通讯
- 自己搭建自动化巡检系统(五) 抖动告警
- 自己搭建自动化巡检系统(四) 处理邻居列表
- 自己搭建自动化巡检系统(四) 处理邻居列表
- 自己搭建自动化巡检系统(五) 抖动告警
- 自己搭建自动化巡检系统(一) 环境准备系统连接gns3
- 自己搭建自动化巡检系统(二) telnet远程登录
- JEECMS站群管理系统-- 自定义标签及使用自己创建的表的实现过程
- C#通过WMI的wind32 的API函数实现msinfo32的本地和远程计算机的系统摘要信息查看功能
- centos7 通过kvm+vnc 实现远程桌面虚拟化和创建windows、Linux虚拟机
- 通过rsync搭建一个远程备份系统(一)
- 通过rsync搭建一个远程备份系统(二)
- 基于GIS变电站综自系统的可视化远程智能巡检系统的实现
- 通过 open falcon 的 agent 的http 接口实现远程系统命令调用
- linux下通过rsync+inotify 实现数据实时备份(远程容灾备份系统)
- linux下通过rsync+inotify 实现数据实时备份(远程容灾备份系统)
- android远程控制(三)----通过后台服务实现系统点击事件模拟