pxnet2768.pixnet.net Open in urlscan Pro
103.23.108.220  Public Scan

Submitted URL: http://pxnet2768.pixnet.net/blog/post/157228756-%E7%B3%BB%E7%B5%B1%E9%81%8B%E7%B6%AD%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%9A%84%E6%...
Effective URL: https://pxnet2768.pixnet.net/blog/post/157228756-%E7%B3%BB%E7%B5%B1%E9%81%8B%E7%B6%AD%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%9A%84%E6%...
Submission: On May 20 via api from US — Scanned from DE

Form analysis 2 forms found in the DOM

POST https://pxnet2768.pixnet.net/blog/postcomment/157228756?tab_type=current

<form class="current-tab-form" method="POST" action="https://pxnet2768.pixnet.net/blog/postcomment/157228756?tab_type=current">
  <input type="hidden" name="sToken" value="81afbaa6129e1d320376d370a071602a">
  <div id="comment-area">
    <div id="comment-area-2">
      <div class="comment-identity identity-logout">
        <div class="choose-identity">
          <a class="openid-pixnet" href="https://member.pixnet.cc/login/openid?done=https%3A%2F%2Fpxnet2768.pixnet.net%2Fblog%2Fpost%2F157228756%3Futm_source%3DPIXNET%26utm_medium%3DBlog_login%23comment-form&amp;openid=https%3A%2F%2Fmember.pixnet.cc%2Flogin&amp;easy_login=1&amp;from_service=Blog"><span class="invisible">PIXNET</span></a>
          <a class="openid-facebook" href="https://member.pixnet.cc/login/facebooklogin?done=http%3A%2F%2Fpxnet2768.pixnet.net%2Fapi%2Fpopuplogin%3Fdone%3Dhttps%253A%252F%252Fpxnet2768.pixnet.net%252Fblog%252Fpost%252F157228756%253Futm_source%253DPIXNET%2526utm_medium%253DBlog_login%2523comment-form&amp;easy_login=1" onclick="window.open(this.href, 'login', config='height=650,width=650,scrollbars=1,resizable=0'); return false;"><span class="invisible">Facebook</span></a>
          <a class="openid-yahoo" href="https://member.pixnet.cc/login/openid?done=http%3A%2F%2Fpxnet2768.pixnet.net%2Fapi%2Fpopuplogin%3Fdone%3Dhttps%253A%252F%252Fpxnet2768.pixnet.net%252Fblog%252Fpost%252F157228756%253Futm_source%253DPIXNET%2526utm_medium%253DBlog_login%2523comment-form&amp;openid=https%3A%2F%2Fme.yahoo.com%2F&amp;without_signup=1" onclick="window.open(this.href, 'login', config='height=650,width=650,scrollbars=1,resizable=0'); return false;"><span class="invisible">Yahoo!</span></a>
          <a class="openid-google" href="https://classic-panel.pixnet.cc/login/googlepluslogin?done=http%3A%2F%2Fpxnet2768.pixnet.net%2Fapi%2Fpopuplogin%3Fdone%3Dhttps%253A%252F%252Fpxnet2768.pixnet.net%252Fblog%252Fpost%252F157228756%253Futm_source%253DPIXNET%2526utm_medium%253DBlog_login%2523comment-form&amp;without_signup=1" onclick="window.open(this.href, 'login', config='height=650,width=650,scrollbars=1,resizable=0'); return false;"><span class="invisible">Google</span></a>
          <a class="openid-msn" href="https://classic-panel.pixnet.cc/login/livelogin?done=http%3A%2F%2Fpxnet2768.pixnet.net%2Fapi%2Fpopuplogin%3Fdone%3Dhttps%253A%252F%252Fpxnet2768.pixnet.net%252Fblog%252Fpost%252F157228756%253Futm_source%253DPIXNET%2526utm_medium%253DBlog_login%2523comment-form&amp;without_signup=1" onclick="window.open(this.href, 'login', config='height=650,width=650,scrollbars=1,resizable=0'); return false;"><span class="invisible">MSN</span></a>
        </div>
      </div>
      <div class="comment-body">
        <p>
          您尚未登入,將以<b>訪客</b>身份留言。亦可<a href="https://member.pixnet.cc/login/openid?done=https%3A%2F%2Fpxnet2768.pixnet.net%2Fblog%2Fpost%2F157228756%3Futm_source%3DPIXNET%26utm_medium%3DBlog_login%23comment-form&amp;openid=https%3A%2F%2Fmember.pixnet.cc%2Flogin&amp;easy_login=1&amp;from_service=Blog">登入</a>留言
        </p>
        <input type="text" name="blogcommenttext_name" id="comment_showname" class="comment-name" placeholder="您的暱稱 ...">
        <div class="comment-textarea comment-textarea--text-right">
          <textarea name="blogcommenttext_body" id="comment_text" placeholder="留個言吧 ..."></textarea>
          <div class="private-message-container">
            <div class="private-message"><label><input type="checkbox" name="blogcomment_open" id="comment_open" value="0" disabled=""><img
                  src="//front.pixfs.net/images/blog/post/mobile/articlecomment/icon-lock--gray.png?v=a38fe6398ecfb90ae75316bf3133600a" width="12" height="12">悄悄話</label></div>
            <div id="nologin_hidden_msg" class="private-notice">
              <a href="https://member.pixnet.cc/login/openid?done=https%3A%2F%2Fpxnet2768.pixnet.net%2Fblog%2Fpost%2F157228756%3Futm_source%3DPIXNET%26utm_medium%3DBlog_login%23comment-form&amp;openid=https%3A%2F%2Fmember.pixnet.cc%2Flogin&amp;easy_login=1&amp;from_service=Blog">登入</a>可留悄悄話
            </div>
          </div>
        </div><!-- .comment-textarea -->
        <div id="comment-area-ad" style="display:none">
        </div>
        <div class="captcha" style="display:none" id="captcha">
          <a id="authcode-link-url" href="#" target="_blank"><img src="//captcha.pixplug.in/image/1.1/7191387570d8dff6a4b864ed7f0fd0db/06f0c0d410c4d6c0617bfa817809ab9e/200x50.jpeg" id="authcode-url" class="authcode-url"></a>
          <div>請輸入左方認證碼:<input type="text" name="authCode" class="text-input"><a class="reload-captcha" href="#">看不懂,換張圖</a></div>
        </div>
        <div class="comment-extra">
          <div id="unfold-comment-extra"><img src="//s.pixfs.net/f.pixnet.net/comment/images/comment-unfold.jpg"> 其他選項</div>
          <button type="submit"><span>送出留言</span></button>
        </div>
        <div id="comment-extra" class="extra" style="display:none"><input type="text" name="blogcommenttext_mail" class="text-input" id="comment_mail" placeholder="電子郵件 ..."><input type="text" name="blogcommenttext_url" class="text-input"
            id="comment_url" placeholder="個人網頁 ..."></div>
      </div><!--.comment-middle-->
    </div><!-- #comment-area-2-->
  </div><!-- #comment-area -->
</form>

POST https://pxnet2768.pixnet.net/blog/search/

<form method="post" action="https://pxnet2768.pixnet.net/blog/search/" id="search-form" data-wording-needkeyword="請輸入關鍵字">
  <ul>
    <li><input name="search-target" id="search-target" type="text"></li>
    <li><input id="search-submit" type="submit" value="搜尋"></li>
  </ul>
</form>

Text Content

 * 
 * 
 * 
 * 
 * 登入
 * 







PIXNET uses cookies to give you the best browsing experience, press agree to
continue using PIXNET. If you choose not to use cookies, please refer to our
privacy policy to see how to disable cookie tracking or delete them.
Agree


愛在屋簷下的部落格

跳到主文


歡迎光臨愛在屋簷下在痞客邦的小天地

部落格全站分類:數位生活

 * 相簿
 * 部落格
 * 留言
 * 名片

 * Oct 27 Tue 2015 12:50


 * 系統運維工程師的法寶:PYTHON PARAMIKO

分享:    

 
paramiko是用python語言寫的一個模塊,遵循SSH2協議,支持以加密和認證的方式,進行遠程服務器的連接。
使用paramiko可以很好的解決以下問題:

需要使用windows客戶端,
遠程連接到Linux服務器,查看上面的日誌狀態,批量配置遠程服務器,文件上傳,文件下載等


"paramiko" is a combination of the esperanto words for "paranoid" and
"friend".  it's a module for python 2.5+ that implements the SSH2 protocol
for secure (encrypted and authenticated) connections to remote machines.
unlike SSL (aka TLS), SSH2 protocol does not require hierarchical
certificates signed by a powerful central authority. you may know SSH2 as
the protocol that replaced telnet and rsh for secure access to remote
shells, but the protocol also includes the ability to open arbitrary
channels to remote services across the encrypted tunnel (this is how sftp
works, for example).


it is written entirely in python (no C or platform-dependent code) and is
released under the GNU LGPL (lesser GPL).


the package and its API is fairly well documented in the "doc/" folder
that should have come with this archive.


Requirements
------------


 - python 2.5 or better
 - pycrypto 2.1 or better


If you have setuptools, you can build and install paramiko and all its
dependencies with this command (as root)::


   easy_install ./


Portability
-----------



i code and test this library on Linux and MacOS X. for that reason, i'm
pretty sure that it works for all posix platforms, including MacOS. it
should also work on Windows, though i don't test it as frequently there.
if you run into Windows problems, send me a patch: portability is important
to me.


some python distributions don't include the utf-8 string encodings, for
reasons of space (misdirected as that is). if your distribution is
missing encodings, you'll see an error like this::


   LookupError: no codec search functions registered: can't find encoding


this means you need to copy string encodings over from a working system.
(it probably only happens on embedded systems, not normal python
installs.) Valeriy Pogrebitskiy says the best place to look is
``.../lib/python*/encodings/__init__.py``.


Bugs & Support
--------------


Please file bug reports at https://github.com/paramiko/paramiko/. There is
currently no mailing list but we plan to create a new one ASAP.


Demo
----


several demo scripts come with paramiko to demonstrate how to use it.
probably the simplest demo of all is this::


   import paramiko, base64
   key = paramiko.RSAKey(data=base64.decodestring('AAA...'))
   client = paramiko.SSHClient()
   client.get_host_keys().add('ssh.example.com', 'ssh-rsa', key)
   client.connect('ssh.example.com', username='strongbad', password='thecheat')

   stdin, stdout, stderr = client.exec_command('ls')
   for line in stdout:
       print '... ' + line.strip('\n')
   client.close()


...which prints out the results of executing ``ls`` on a remote server.
(the host key 'AAA...' should of course be replaced by the actual base64
encoding of the host key.  if you skip host key verification, the
connection is not secure!)


the following example scripts (in demos/) get progressively more detailed:


:demo_simple.py:
   calls invoke_shell() and emulates a terminal/tty through which you can
   execute commands interactively on a remote server.  think of it as a
   poor man's ssh command-line client.


:demo.py:
   same as demo_simple.py, but allows you to authenticiate using a
   private key, attempts to use an SSH-agent if present, and uses the long
   form of some of the API calls.


:forward.py:
   command-line script to set up port-forwarding across an ssh transport.
   (requires python 2.3.)


:demo_sftp.py:
   opens an sftp session and does a few simple file operations.


:demo_server.py:
   an ssh server that listens on port 2200 and accepts a login for
   'robey' (password 'foo'), and pretends to be a BBS.  meant to be a
   very simple demo of writing an ssh server.


:demo_keygen.py:

   an key generator similar to openssh ssh-keygen(1) program with
   paramiko keys generation and progress functions.


Use
---


the demo scripts are probably the best example of how to use this package.
there is also a lot of documentation, generated with epydoc, in the doc/
folder.  point your browser there.  seriously, do it.  mad props to
epydoc, which actually motivated me to write more documentation than i
ever would have before.


there are also unit tests here::


   $ python ./test.py


which will verify that most of the core components are working correctly.


-、執行遠程命令:
#!/usr/bin/python
#coding:utf-8
import paramiko
port =22
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("*.*.*.*",port,"username", "password")
stdin, stdout, stderr = ssh.exec_command("你的命令")
print stdout.readlines()
ssh.close()


二、上傳文件到遠程
#!/usr/bin/python
#coding:utf-8
import paramiko



port =22
t = paramiko.Transport(("IP",port))
t.connect(username = "username", password = "password")
sftp = paramiko.SFTPClient.from_transport(t)
remotepath='/tmp/test.txt'
localpath='/tmp/test.txt'
sftp.put(localpath,remotepath)
t.close()


三、從遠程下載文件
#!/usr/bin/python
#coding:utf-8
import paramiko


port =22
t = paramiko.Transport(("IP",port))
t.connect(username = "username", password = "password")
sftp = paramiko.SFTPClient.from_transport(t)
remotepath='/tmp/test.txt'
localpath='/tmp/test.txt'
sftp.get(remotepath, localpath)
t.close()


四、執行多個命令
#!/usr/bin/python
#coding:utf-8


import sys
sys.stderr = open('/dev/null')       # Silence silly warnings from paramiko
import paramiko as pm
sys.stderr = sys.__stderr__
import os


class AllowAllKeys(pm.MissingHostKeyPolicy):
   def missing_host_key(self, client, hostname, key):

       return


HOST = '127.0.0.1'
USER = ''
PASSWORD = ''


client = pm.SSHClient()
client.load_system_host_keys()
client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
client.set_missing_host_key_policy(AllowAllKeys())
client.connect(HOST, username=USER, password=PASSWORD)


channel = client.invoke_shell()
stdin = channel.makefile('wb')
stdout = channel.makefile('rb')


stdin.write('''
cd tmp
ls
exit
''')
print stdout.read()


stdout.close()
stdin.close()
client.close()


五、獲取多個文件
#!/usr/bin/python
#coding:utf-8


import paramiko
import os


ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('localhost',username='****')


apath = '/var/log'
apattern = '"*.log"'
rawcommand = 'find {path} -name {pattern}'
command = rawcommand.format(path=apath, pattern=apattern)
stdin, stdout, stderr = ssh.exec_command(command)
filelist = stdout.read().splitlines()


ftp = ssh.open_sftp()
for afile in filelist:
   (head, filename) = os.path.split(afile)
   print(filename)
   ftp.get(afile, './'+filename)
ftp.close()
ssh.close()




全站熱搜

日本旅遊韓國旅遊澎湖花火節旅遊趣民宿推薦電影影評

創作者介紹
愛在屋簷下

愛在屋簷下的部落格



by Taboolaby Taboola
GEERS

Saalfeld: GEERS sucht 700 Testhörer vor 1972 geborenGEERS|
贊助贊助


Undo

【健美也要健心】 @ 運動黑魔法-類固醇交流天地 :: 痞客邦 ::


Undo
Hör-Profis

Einfacher Trick ermöglicht Top-Hörgeräte für 10€Hör-Profis|
贊助贊助


Undo

因為是他,因為是我 - Parce que c'était lui, parce que c'était moi. / 蒙田 Montainge @ 九月的春天
- On connaît la chanson :: 痞客邦 ::


Undo

性感綻放三角褲。內褲。居家。性感。蕾絲內褲。低腰。包臀。台灣製。K031《玉如阿姨》心得分享 @ 推薦必買 :: 痞客邦 ::


Undo
Vergleich Profis24

Solar-Boom 2023: Staat gibt jetzt unfassbaren AnreizVergleich Profis24|
贊助贊助


Undo




愛在屋簷下 發表在 痞客邦 留言(0) 人氣(12020)

E-mail轉寄


 * 全站分類:數位生活
 * 上一篇: linux路由子系統學習
 * 下一篇: python之Property屬性用法

▲top


留言列表 (0)

發表留言

PIXNET Facebook Yahoo! Google MSN

您尚未登入,將以訪客身份留言。亦可登入留言

悄悄話
登入可留悄悄話

請輸入左方認證碼:看不懂,換張圖
其他選項
送出留言


站方公告

 * [教學]「Xuite 隨意窩」文章搬家教學*更新*
 * [公告] 2023年度農曆春節期間服務公告
 * [公告] 2022/09/02 相簿、部落格功能維護公告

活動快報


你加入...

看更多活動好康



個人資訊


暱稱:愛在屋簷下 分類:數位生活 好友:共0位 (看全部)

我的好友

沒有資料可以顯示

熱門文章

 * (47471)C語言中define的使用方法總結
 * (25405)C#的DllImport用法
 * (21249)linux下svn命令使用大全
 * (18136)linux下syslog使用說明
 * (12019)系統運維工程師的法寶:python paramiko

文章分類

   
 * 未分類文章 (51)
   

最新文章

 * 一次利用nginx漏洞的木馬事件
 * virtualbox安裝時/etc/init.d/vboxdrv錯誤的解決
 * C#的DllImport用法
 * Python特色的詳細介紹
 * oracle redo日誌維護

最新留言

   
 * 04/29 我叫黎兒女生最近內心掙扎著要不要約炮我的line:woyou58: 我叫黎兒女生最近內心掙扎...
   
 * 10/11 蔡宏恩:請問大大 用dllimport跟我直...
   

動態訂閱

 * 痞客邦站方公告 文章更新
   [教學]「Xuite 隨意窩」文章搬家教學*更新*
   1個月前
 * 痞客邦站方公告 文章更新
   [公告] 2023年度農曆春節期間服務公告
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告] 2022/09/02 相簿、部落格功能維護公告
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告] 2022/08/22、08/23 應用市集部分功能維護公告
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告] 痞客邦 APP 全新服務上線 - 美食優惠券
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告] 痞客邦外部 JavaScript 語法使用規範
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告]痞客邦會員任務全新改版,最新、最熱、最好康的星際任務都在名片頁!
   超過3個月以上
 * 痞客邦站方公告 文章更新
   [公告] 痞客邦新功能「POI - 餐廳卡片」,2 步驟快速提高內容呈現
   超過3個月以上
 * 痞客邦站方公告 文章更新
   「部落格舊編輯模擬器」擴充功能正式上線囉!
   超過3個月以上
 * 痞客邦站方公告 文章更新
   PIXNET 將於 2019/05/20 全面使用 ads.txt 宣告授權數位賣方
   超過3個月以上

所有訂閱

文章精選

文章精選 2015 十二月 (11) 2015 十一月 (7) 2015 十月 (6) 2015 九月 (5) 2015 七月 (21) 2015 六月 (1)
所有文章列表

文章搜尋

 * 
 * 

新聞交換(RSS)

 * 
   
 * 
   
 * 
   

誰來我家



參觀人氣

 * 本日人氣:1
 * 累積人氣:167268

QR CODE



POWERED BY

 * 
 * (登入)





回到頁首 回到主文 免費註冊 客服中心 痞客邦首頁 © 2003 - 2023 PIXNET












 * 
   0
 * 
   0
 * 
   0
 * 
   0
   

精選高CP值餐券 等你來搶購!
5月20日 週六







關閉視窗