Python實現TCP/IP協議下的連接埠轉寄及重新導向樣本

首先,我們用webpy寫一個簡單的網站,監聽8080連接埠,返回“Hello, EverET.org”的頁面。然後我們使用我們的forwarding.py,在80連接埠和8080連接埠中間建立兩條通訊管道用於雙向通訊。此時,我們通過80連接埠訪問我們的伺服器。瀏覽器得到:然後,我們在forwarding.py的輸出結果中可以看到瀏覽器和webpy之間的通訊內容。代碼:#!/usr/bin/env pythonimport sys, socket, time, threadingloglock =

在漏洞利用Python代碼真的很爽

不知道怎麼忽然想看這個,呵呵 小我的python的反shell的代碼 #!/usr/bin/python # Python Connect-back Backdoor # Author: wofeiwo # Version: 1.0 # Date: July 15th 2006 import sys import os import socket shell = "/bin/sh" def usage(programname): print "Python Connect-back

Python struct.unpack

1. 設定fomat格式,如下: 複製代碼 代碼如下:# 取前5個字元,跳過4個字元華,再取3個字元 format = '5s 4x 3s' 2. 使用struck.unpack擷取子字串 複製代碼 代碼如下:import struct print struct.unpack(format, 'Test astring') #('Test', 'ing') 來個簡單的例子吧,有一個字串'He is not very happy',處理一下,把中間的not去掉,然後再輸出。 複製代碼

Python字元轉換

如:>>> print ord('a') 97 >>> print chr(97) a 下面我們可以開始來設計我們的大小寫轉換的程式了: 複製代碼 代碼如下:#!/usr/bin/env python #coding=utf-8 def UCaseChar(ch): if ord(ch) in range(97, 122): return chr(ord(ch) - 32) return ch def LCaseChar(ch): if ord(ch) in range(65, 91):

Python splitlines提示

複製代碼 代碼如下:mulLine = """Hello!!! Wellcome to Python's world! There are a lot of interesting things! Enjoy yourself. Thank you!""" print ''.join(mulLine.splitlines()) print '------------' print ''.join(mulLine.splitlines(True)) 輸出結果: Hello!!! Wellcome

Python strip lstrip rstrip使用方法

注意的是,傳入的是一個字元數組,編譯器去除兩端所有相應的字元,直到沒有匹配的字元,比如: 複製代碼 代碼如下:theString = 'saaaay yes no yaaaass' print theString.strip('say') theString依次被去除首尾在['s','a','y']數組內的字元,直到字元在不數組內。所以,輸出的結果為: yes no 比較簡單吧,lstrip和rstrip原理是一樣的。注意:當沒有傳入參數時,是預設去除首尾空格的。 複製代碼

Python translator使用執行個體

1.string.maketrans設定字串轉換規則表(translation table) 複製代碼 代碼如下:allchars = string.maketrans('', '')#所有的字串,即不替換字串 aTob = string.maketrans('a','b')#將字元a轉換為字元b 2.translate函數進行字串的替換和刪除,第一個參數是字串轉換規則表(translation table),第二個參數是要刪除的字串。比如,要將字串s中的所有e替換為a,同時要刪除所有的o

Python 時間處理datetime執行個體

同時,關於datetime也是簡單介紹。因為有很多東西需要自己去使用,去查協助才最有效。例子:計算上一個星期五並輸出。解答:複製代碼 代碼如下: import datetime, calendar lastFriday = datetime.date.today( ) oneday = datetime.timedelta(days=1) lastFriday -= oneday while lastFriday.weekday( ) != calendar.FRIDAY:

Python httplib,smtplib使用方法

例一:使用httplib訪問某個url然後擷取返回的內容:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import httplibconn=httplib.HTTPConnection("www.cnblogs.com")conn.request("GET", "/coderzh/archive/2008/05/13/1194445.html")

python ElementTree 基本讀操作樣本

樣本可以附件中下載 1.載入xml檔案 載入XML檔案共有2種方法,一是載入指定字串,二是載入指定檔案 2.擷取element的方法 a) 通過getiterator b) 過 getchildren c) find方法 d) findall方法 樣本如下: 複製代碼 代碼如下:#-*- coding:utf-8 -*- from xml.etree import ElementTree def print_node(node): '''''列印結點基本資料''' print "========

Python 拷貝對象(深拷貝deepcopy與淺拷貝copy)

1. copy.copy 淺拷貝 只拷貝父物件,不會拷貝對象的內部的子物件。2. copy.deepcopy 深拷貝 拷貝對象及其子物件一個很好的例子:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import copya = [1, 2, 3, 4, ['a', 'b']] #原始對象b = a #賦值,傳對象的引用c =

Python enumerate遍曆數組樣本應用

其他語言中,比如C#,我們通常遍曆數組是的方法是:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->for (int i = 0; i list.Length; i++){ //todo with list[i]}在Python中,我們習慣這樣遍曆:Code highlighting produced by Actipro

Python函數學習筆記

局部名字靜態檢測 Python探測局部範圍的時候:是在python編譯代碼時檢測,而不是通過他們在運行時的賦值。 正常的情況下,沒在函數中複製的名字將在包含它的模組中尋找: >>> x=99 >>> def selector(): ... print x ... >>> selector() 99 但是: >>> def selector(): ... print x ... x=100 ... >>> selector() Traceback (most recent call last):

Python 初始化多維陣列代碼

Python中初始化一個5 x 3每項為0的數組,最好方法是:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->multilist = [[0 for col in range(5)] for row in range(3)]我們知道,為了初始化一個一維數組,我們可以這樣做:Code highlighting produced by Actipro

合并Excel工作薄中成績表的VBA代碼,非常適合教育一線的朋友

這時候還需要把各個工作表合并到一起來形成一個匯總表。這時候比較麻煩也比較容易出錯,因為各個表的學號不一定都是一致的、對齊的。因為可能會有人缺考,有人會考號塗錯等等。特奉獻以下代碼,用於合并學產生績表或者其它類似的表都可以。本代碼特點在於不需要使用SQL或者Access等大頭軟體,只需要Excel就可以執行,非常方便,速度也不慢。轉載請勿清除廣告。 沒有合適的區域網路管理軟體嗎?你的網管工具夠靈活夠高效嗎?看看這個network management software。 ' ===========

Python 深入理解yield

只是粗略的知道yield可以用來為一個函數傳回值塞資料,比如下面的例子:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->def addlist(alist): for i in alist: yield i + 1取出alist的每一項,然後把i + 1塞進去。然後通過調用取出每一項:Code highlighting

Python __getattr__與__setattr__使用方法

比如下面的例子:class Book(object): def __setattr__(self, name, value): if name == 'value': object.__setattr__(self, name, value - 100) else: object.__setattr__(self, name, value) def __getattr__(self, name):

Python 連連看串連演算法

功能:為連連看遊戲提供串連演算法 說明:模組中包含一個Point類,該類是遊戲的基本單元“點”,該類包含屬性:x,y,value。 其中x,y代表了該點的座標,value代表該點的特徵:0代表沒有被填充,1-8代表被填充為遊戲圖案,9代表被填充為牆壁 模組中還包含一個名為points的Point列表,其中儲存著整個遊戲介面中的每個點 使用模組的時候應首先調用createPoints方法,初始化遊戲介面中每個點,然後可通過points訪問到每個點,繼而初始化介面

Python類的基礎入門知識

複製代碼 代碼如下:class Account(object): "一個簡單的類" account_type="Basic" def __init__(self,name,balance): "初始化一個新的Account執行個體" self.name=name self.balance=balance def deposit(self,amt): "存款" self.balance=self.balance+amt def withdraw(self,amt): "取款"

Python 調用VC++的動態連結程式庫(DLL)

1. 首先VC++的DLL的匯出函數定義成標準C的匯出函數: 複製代碼 代碼如下:#ifdef LRDLLTEST_EXPORTS #define LRDLLTEST_API __declspec(dllexport) #else #define LRDLLTEST_API __declspec(dllimport) #endif extern "C" LRDLLTEST_API int Sum(int a , int b); extern "C" LRDLLTEST_API void

總頁數: 2974 1 .... 2575 2576 2577 2578 2579 .... 2974 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.