hysaoh 发表于 2023-1-11 21:45:26

python解决ssh记不住ip的问题

> 本帖最后由 hysaoh 于 2023-1-11 21:48 编辑

楼主有好几台服务器,由于服务器过多导致记住服务器ip成了问题,于是写了这个脚本,能够更好的进行快乐的ssh。代码如下。
请注意,需要安装rich第三方库,其他均为自带库。
在我的windows terminal中效果如图
```py
# -*- coding: utf-8 -*-
"""
@Author         :Cat
@Date         : 2023年 01月 10日
@Introduction   :A Lazy Cat
"""
import shlex
import subprocess
from rich.console import Console
from rich.table import Table

console = Console()

table = Table(title="服务器列表")
table.add_column("序号", style="cyan")
table.add_column("服务器", style="cyan")
table.add_column("IP", style="cyan")

serverList = {
    "阿里云服务器": "x.x.x.x",
    "腾讯云服务器": "x.x.x.x",
    "本地虚拟机:AlmaLinux": "192.168.197.129",
    "本地虚拟机:CentOS7网络络自动运维": "192.168.197.191"
}
keys = list(serverList.keys())
for i in range(len(keys)):
    table.add_row(str(i), keys, serverList])
console.print(table)
console.print("请选择要连接的服务器序号:", style="green", end="")
index = int(input())
console.print("正在连接服务器:" + keys, style="green")
cmd = "ssh root@" + serverList]
res = subprocess.Popen(shlex.split(cmd), shell=True).communicate()
```

hysaoh 发表于 2023-1-11 21:47:56

不知道为什么看不到图片,具体效果放到这里了。不知道能不能看到。

王一之 发表于 2023-1-12 09:31:55

我用ssh termius工具,直接一个列表

常用的话,记得ip前面一点,就可以自动提示

hysaoh 发表于 2023-1-15 13:43:12

王一之 发表于 2023-1-12 09:31
我用ssh termius工具,直接一个列表

常用的话,记得ip前面一点,就可以自动提示


有时间了也搞个自动提示

朱焱伟 发表于 2023-11-18 19:14:43

(https://github.com/Gcaufy/sshman)

hysaoh 发表于 2023-11-29 09:18:27

可以的,也不错!
页: [1]
查看完整版本: python解决ssh记不住ip的问题