python3swampy
① 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个元素分别表示'每次遍历的路径名,目录列表和文件列表',只遍历目录!