當前位置:首頁 » 編程語言 » python3swampy

python3swampy

發布時間: 2022-04-26 13:29:25

python3.2 下的抓包庫。。無論是pypcap還是scapy。貌似都沒有py3的版本。。跪求一個可以python3用

有一個py3kcap是pycap的封裝版本,可以用於python3版本。

給你一個使用的示例代碼:

#!/usr/bin/env python3.2
import ctypes,sys
from ctypes.util import find_library
#pcap = ctypes.cdll.LoadLibrary("libpcap.so")
pcap = None
if(find_library("libpcap") == None):
print("We are here!")
pcap = ctypes.cdll.LoadLibrary("libpcap.so")
else:
pcap = ctypes.cdll.LoadLibrary(find_library("libpcap"))
# required so we can access bpf_program->bf_insns
"""
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;}
"""
class bpf_program(ctypes.Structure):
_fields_ = [("bf_len", ctypes.c_int),("bf_insns", ctypes.c_void_p)]
class sockaddr(ctypes.Structure):
_fields_=[("sa_family",ctypes.c_uint16),("sa_data",ctypes.c_char*14)]
class pcap_pkthdr(ctypes.Structure):
_fields_ = [("tv_sec", ctypes.c_long), ("tv_usec", ctypes.c_long), ("caplen", ctypes.c_uint), ("len", ctypes.c_uint)]

pkthdr = pcap_pkthdr()
program = bpf_program()
# prepare args
snaplen = ctypes.c_int(1500)
#buf = ctypes.c_char_p(filter)
optimize = ctypes.c_int(1)
mask = ctypes.c_uint()
net = ctypes.c_uint()
to_ms = ctypes.c_int(100000)
promisc = ctypes.c_int(1)
filter = bytes(str("port 80"), 'ascii')
buf = ctypes.c_char_p(filter)
errbuf = ctypes.create_string_buffer(256)
pcap_close = pcap.pcap_close
pcap_lookupdev = pcap.pcap_lookupdev
pcap_lookupdev.restype = ctypes.c_char_p
#pcap_lookupnet(dev, &net, &mask, errbuf)
pcap_lookupnet = pcap.pcap_lookupnet
#pcap_t *pcap_open_live(const char *device, int snaplen,int promisc, int to_ms,
#char *errbuf
pcap_open_live = pcap.pcap_open_live
#int pcap_compile(pcap_t *p, struct bpf_program *fp,const char *str, int optimize,
#bpf_u_int32 netmask)
pcap_compile = pcap.pcap_compile
#int pcap_setfilter(pcap_t *p, struct bpf_program *fp);
pcap_setfilter = pcap.pcap_setfilter
#const u_char *pcap_next(pcap_t *p, struct pcap_pkthdr *h);
pcap_next = pcap.pcap_next
# int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *program,
# const char *buf, int optimize, bpf_u_int32 mask);
pcap_geterr = pcap.pcap_geterr
pcap_geterr.restype = ctypes.c_char_p
#check for default lookup device
dev = pcap_lookupdev(errbuf)
#override it for now ..
dev = bytes(str("wlan0"), 'ascii')
if(dev):
print("{0} is the default interface".format(dev))
else:
print("Was not able to find default interface")

if(pcap_lookupnet(dev,ctypes.byref(net),ctypes.byref(mask),errbuf) == -1):
print("Error could not get netmask for device {0}".format(errbuf))
sys.exit(0)
else:
print("Got Required netmask")
handle = pcap_open_live(dev,snaplen,promisc,to_ms,errbuf)
if(handle is False):
print("Error unable to open session : {0}".format(errbuf.value))
sys.exit(0)
else:
print("Pcap open live worked!")
if(pcap_compile(handle,ctypes.byref(program),buf,optimize,mask) == -1):
# this requires we call pcap_geterr() to get the error
err = pcap_geterr(handle)
print("Error could not compile bpf filter because {0}".format(err))
else:
print("Filter Compiled!")
if(pcap_setfilter(handle,ctypes.byref(program)) == -1):
print("Error couldn't install filter {0}".format(errbuf.value))
sys.exit(0)
else:
print("Filter installed!")
if(pcap_next(handle,ctypes.byref(pkthdr)) == -1):
err = pcap_geterr(handle)
print("ERROR pcap_next: {0}".format(err))
print("Got {0} bytes of data".format(pkthdr.len))
pcap_close(handle)

② python3.6中如何導入第三方庫,庫沒有setup.py

pip能用,3以上的版本都自帶pip的,可能是你電腦上有多個pip。先cd到pip目錄,再運行pip安裝模塊。

③ python3 rece函數是不是被移除了

在Python 3里,rece()函數已經被從全局名字空間里移除了,它現在被放置在fucntools模塊里

④ 這個小句子在python3中能跳出循環嗎,幫忙改下謝謝

可以跳出,但是len(s)那一段沒任何意義吧

⑤ 這段代碼在python3中怎麼運行

在Python中有兩種編寫代碼的形式:Shell形式:一次只能執行一條完整語句,包括 if判斷,for的循環,或者定義一個class,定義一個函數等等,這種很不靈活,容易出現所述現象:Edit形式:將要寫的代碼保存到一個PY文件裡面,執行的代碼無限制;打開方法為:File-New Window:使用Edit模式,可以避免遇到的問題。

⑥ 關於python3凱撒密碼代碼的問題

prompt="""**************************
*CaesarCipherEncryption*
**************************
"""
print(prompt)
alphabet="abcdefghijklmnopqrstuvwxyz"
shift=5
letter_word=input("Pleaseentera5letterword:")
length=len(alphabet)
result=[]
forcinletter_word:
i=alphabet.index(c.lower())
i=(i+5)%length
result.append(alphabet[i])
result=''.join(result)
print("Encryptedword:{0}".format(result))

⑦ python怎麼安裝swampy包

windos下
下面是安裝python的swampy模塊的方法:

1、下載setuptools:https://pypi.python.org/pypi/setuptools/1.1.4

2、解壓縮,雙擊文件夾里的ez_setup.py

3、進入命令提示符界面,進入E:/python27/Scripts,在命令提示符界面運行:easy_install.exe swampy

4、在IDLE中輸入import swampy.TurtleWorld
沒有報錯即表示swampy安裝成功。

linux

linux下載swampy-2.1.7.tar.gz的安裝包,

tar -xzv -f *** -C *** 解壓文件到指定文件夾,這里發生了一個插曲,下載的文件不全生成的是.tar.gz.part文件,卻沒注意。.part文件是指壓縮文件的一部分,也就是不全啦。

接下來怎麼使用swampy,按照thinkpython官方的說法是

一。 install as package

二 。work in the directory that contains the Swampy files

三。add that directory to Python's search path

⑧ Python3 請問這個代碼哪裡錯了

這個可能是類型的問題。你將input()改成raw_input()就可以解決問題。


不過似乎python3沒有raw_input了。


你檢查一下你的state=input()中的類型。

print (type(state))


你再對比一個你的cities中的keys的類型

print(type((cities.keys())[0]))
printcities['CA']

--

如果兩者的類型有差異,你就需要轉換一下。

比如將state轉換一下

state=str(state)


此外你輸入的時候,有沒有加引號? 這個也是要考慮的問題。


剛剛在linux上安裝了一個python3,我測試的結果是,你輸入state時,不要加引號。比如直接輸入大寫的CA就會出San Francisco

程序沒有問題。只是python2與python3輸入的時候,python2需要引號,python3不需要。

⑨ 神力科莎點start後顯示python33.dll丟失

樓主你好,你可以重新下載一個python33.dll文件,然後按如下步驟操作:
一、解壓後直接拷貝該文件到系統目錄里:
1、Windows 95/98/Me系統,復制到C:WindowsSystem目錄下。
2、Windows NT/2000系統,復制到C:WINNTSystem32目錄下。
3、Windows XP/WIN7/Vista系統,復制到C:WindowsSystem32目錄下。
4、如果您的系統是64位的請將文件復制到C:WindowsSysWOW64目錄
二、打開"開始-運行-輸入regsvr32 python33.dll",回車即可解決。
上傳並提供下載連接,可根據需要下載。

python33.dll文件下載地址:http://www.edowning.net/soft/102547.htm

⑩ python3 裡面有os.path.walk嗎

1>參數top表示需要遍歷的目錄樹的路徑
2>參數topdown的默認值是"True",表示首先返回目錄樹下的文件,然後在遍歷目錄樹的子目錄.Topdown的值為"False"時,則表示先遍歷目錄樹的子目錄,返回子目錄下的文件,最後返回根目錄下的文件
3>參數onerror的默認值是"None",表示忽略文件遍歷時產生的錯誤.如果不為空,則提供一個自定義函數提示錯誤信息後繼續遍歷或拋出異常中止遍歷
4>該函數返回一個元組,該元組有3個元素,這3個元素分別表示'每次遍歷的路徑名,目錄列表和文件列表',只遍歷目錄!

熱點內容
同時修改多台伺服器管理地址工具 發布:2025-05-16 09:20:36 瀏覽:421
什麼配置就能玩地平線 發布:2025-05-16 09:13:46 瀏覽:82
python旋轉圖片 發布:2025-05-16 09:13:40 瀏覽:638
少女前線防檢測腳本 發布:2025-05-16 08:59:07 瀏覽:728
編譯器對系統的依賴 發布:2025-05-16 08:37:29 瀏覽:711
javamap數組 發布:2025-05-16 08:37:28 瀏覽:451
移動光貓如何自行修改密碼 發布:2025-05-16 08:20:15 瀏覽:125
作為基線存儲 發布:2025-05-16 08:15:22 瀏覽:859
安卓怎麼關閉手機應用推薦 發布:2025-05-16 08:03:38 瀏覽:930
sql內置函數 發布:2025-05-16 08:03:34 瀏覽:923