import paramikoimport threading
class ftpclient(object):
def __init__(self):
self.ssh = paramiko.sshclient()
def sftp_connect(self, hostname, port, username, passwd):
transprot = paramiko.transport((hostname, port))
transprot.connect(username=username, password=passwd)
self.sftp = paramiko.sftpclient.from_transport(transprot)
def ssh_connect(self, hostname, port, username, passwd):
self.ssh.set_missing_host_key_policy(paramiko.autoaddpolicy())
self.ssh.connect(hostname=hostname, port=port, username=username, password=passwd)
def cmd_ssh(self, *args):
while true:
cmd = input(">>>")
if cmd == 'q':
exit()
stin, stdout, stderr = self.ssh.exec_command(cmd)
res, err = stdout.read(), stderr.read()
result = res if res else err
print(result.decode())
def interactive(self):
while true:
cmd = input(">>>").strip()
if not cmd:
continue
if cmd == 'q':
exit()
cmd_str = cmd.split()[0]
if hasattr(self, "%s" % cmd_str): #判斷使用者輸入的命令是否存在
func = getattr(self, "%s" % cmd_str) # 如果self物件中有屬性cmd_str則列印cmd_str的值
func(cmd)
def get(self, *args):
filename = args[0].split()[1]
self.sftp.put(filename, filename)
host_list = ['192.168.15.94', '192.168.15.210']
host_action = ["action", "put"]
def login():
while true:
port = input("請輸入埠》").strip()
if port.isdigit():
port = int(port)
else:
continue
username = input("請輸入使用者名稱》").strip()
if not username:
print("使用者為空")
continue
elif username.isdigit():
print("無數字開頭使用者")
continue
passwd = input("請輸入密碼》").strip()
if not passwd:
print("密碼為空")
continue
return [port, username, passwd] #轉為乙個列表
def main():
while true:
for index, host in enumerate(host_list):
print(index, host)
choice_host = input("請輸入你要進去的主機列表》").strip()
if choice_host.isdigit() and int(choice_host) < len(host_list):
choice_host = int(choice_host)
print('\033[41;1m %s \033[0m' % (host_list[choice_host]))
print("\t")
else:
continue
for index2, host2 in enumerate(host_action):
print(index2, host2)
choice_host_action = input("請輸入你做的操作》").strip()
if choice_host_action.isdigit() and int(choice_host_action) < len(host_action):
choice_host_action = int(choice_host_action)
print('\033[41;1m %s \033[0m' % (host_action[choice_host_action]))
print("\t")
hostname = host_list[int(choice_host)]
if choice_host_action == 0:
while true:
connect_list = login()
port = connect_list[0]
username = connect_list[1]
passwd = connect_list[2]
try:
ftp = ftpclient()
ftp.ssh_connect(hostname, port, username, passwd)
ftp.cmd_ssh()
except importerror as e:
print("有錯誤")
elif choice_host_action == 1:
while true:
connect_list = login()
port = connect_list[0]
username = connect_list[1]
passwd = connect_list[2]
try:
sftp = ftpclient()
sftp.ssh_connect(hostname, port, username, passwd)
sftp.cmd_ssh()
except importerror as e:
print("有錯誤")
else:
print("沒有這個編號!!")
p = threading.thread(target=main,args=())
p.start()
Jumpserver堡壘機簡單配置
jumpserver 是一款由python編寫完全開源的跳板機 堡壘機 系統,實現了跳板機應有的功能。基於ssh協議來管理,客戶端無需安裝agent。此文簡要介紹實際操作時,簡單配置過程。jumpserver基於centos7安裝,可參考 centos7一步步安裝jumpserver堡壘機 官方教程...
堡壘機技術
有一句名言 堡壘往往從內部攻破。在資訊化社會,資訊保安發展的程序,已經清晰地印證了這個道理。如何加固組織機構內部網路的 內防體系 有效防範打擊 內鬼 杜絕因為內部隱患而導致的資訊遭竊密 資料被篡改 系統被破壞等嚴重後果,成為近年內國際資訊保安業界在內網安全領域的新課題。資料內控,也自然成為整個行業市...
天融信堡壘機
恢復出廠設定後的網口配置 使用console口登入root,密碼 njhsecxinan 2016 2 或 jhsec iam2015 編輯 vim etc network inte ce 將以下內容貼到裡面 auto lo iface lo inet loopback allow hotplug ...