数通中规划lld表格做脚本是怎么做
时间: 2024-03-15 09:47:05 浏览: 14
在数通中,规划LLD表格的脚本可以使用Python编写,主要步骤如下:
1. 使用Python的pandas库读取LLD表格。
2. 使用Python的for循环遍历每一行数据,并提取出相邻设备的信息。
3. 使用Python的SSH库连接到相邻设备,并执行相应的命令(例如show cdp neighbors)获取相邻设备的信息。
4. 使用Python的pandas库将获取的相邻设备信息写入到LLD表格中,以便后续使用。
示例代码如下:
```python
import pandas as pd
import paramiko
# 读取LLD表格
lld_table = pd.read_excel('lld_table.xlsx')
# 遍历每一行数据
for index, row in lld_table.iterrows():
# 提取相邻设备信息
local_device = row['Local Device']
local_interface = row['Local Interface']
remote_device = row['Remote Device']
remote_interface = row['Remote Interface']
# 连接到相邻设备
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(remote_device, username='username', password='password')
# 执行命令获取相邻设备信息
stdin, stdout, stderr = ssh.exec_command('show cdp neighbors')
output = stdout.read().decode()
# 提取相邻设备信息并写入LLD表格
remote_interface_info = output.split(remote_interface)[1].split('\n')[0].strip()
remote_device_info = remote_interface_info.split()[0]
lld_table.loc[index, 'Remote Device Info'] = remote_device_info
lld_table.loc[index, 'Remote Interface Info'] = remote_interface_info
# 关闭SSH连接
ssh.close()
# 将LLD表格写入文件
lld_table.to_excel('lld_table_updated.xlsx', index=False)
```
这是一个简单的示例,实际使用时需要根据实际情况进行修改和完善。同时,需要注意安全性问题,例如在连接到设备时使用SSH密钥认证等。