日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python + expect + list = goto myip

發布時間:2023/12/18 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python + expect + list = goto myip 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

對于工程師來講,服務器是必不可少的工具,我們上班大部分時間是在使用ssh這樣的軟件去登錄,但是林子大了,啥鳥都有,群體需要保護,在你和服務器之間,有了堡壘機,每次登錄都需要先登錄堡壘機,然后登錄服務器,So,

難道我們想浪費我們價值1000$/hour的time在登錄服務器的過程中嗎? 當然Say: NO!

思路很簡單,
1. 我們需要借助expect來模擬我們登錄服務器的過程。文件名denglu
2. 我們需要借助一個賬號密碼本,來記錄我們的ip地址和對應的password。文件名list
3. 我們需要一個腳本來連接denglu和list。文件名goto

總結:
goto myip

讀取list找到對應的ip地址和對應的密碼
調用denglu來模擬登錄

/bin/goto

#!/usr/bin/env python #coding: utf8 # fileName: gotoimport os,sys,rehost = sys.argv[1]matchedline = [] for line in open("/bin/list"):result = re.findall(host,line)if len(result) == 1:matchedline.append(line)if len(matchedline) == 1:secretline=matchedline[0]print "Found the machted line."value = re.findall("\S+",secretline)if len(value) == 2:print "Get the password from file."print valueelse:print "Please check your config file list."exit(1)print valuehost = value[0]passwd = value[1]os.system("/bin/denglu %s \"%s\""%(host, passwd)) else:print "No Not Find Matched. Exit............."

/bin/denglu

#!/usr/bin/expect -f # fileName: denglu#log_file /tmp/1.txtset username "yourName" set password "yourPasswd"# This is very important. set HOST [lindex $argv 0] set serverpassword [lindex $argv 1] set timeout 30#發給自己看的 #send_user "$serverpassword" #exit# connect via ssh spawn ssh -o StrictHostKeyChecking=no xxx@xxx.xxx.xxx -p xxxx####################### expect {-re "yes/no.*" {exp_send "yes\r"exp_continue}-re "password:.*" {exp_send "$password\r"} }expect {-re ">.*" {exp_send "ssh root@$HOST\r"} }expect {-re "yes/no.*" {exp_send "yes\r"exp_continue}-re "assword:.*" {exp_send "$serverpassword\r"#puts $serverpasswordputs "**********"}-re "yes/no.*" {exp_send "yes\r"exp_continue} }expect {-re "yes/no.*" {exp_send "yes\r"exp_continue}-re "#.*" {interact}}

/bin/list

ip1 password1 ip2 password2

goto denglu list三個文件我都放在了/bin下面,當然chmod a+x一下,然后使用命令goto ip1來登錄。

Enjoy~

總結

以上是生活随笔為你收集整理的python + expect + list = goto myip的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。