python2.6(windows 7)下安装pycap、sendpkt、dpkt

转自:http://flyingzl.iteye.com/blog/600032

查看下简介

pycap:http://code.google.com/p/pypcap/
sendpkt:http://code.google.com/p/sendpkt/
dpkt:http://code.google.com/p/dpkt/


我的系统是window7、python2.6。pycap和sendpkt结合起来做网络抓包分析非常好,可惜google code上提供的都是针对python2.5的,我的是python2.6,没有办法,只好自己去编译。

编译采用mingw编译,可以到http://www.mingw.org/上去下载,下载后安装然后添加安装路径到环境变量,看到如下效果即可:

Java代码   收藏代码
  1. C:\>g++ --help  
  2. Usage: g++ [options] file...  
  3. Options:  
  4.   -pass-exit-codes         Exit with highest error code from a phase  
  5.   --help                   Display this information  
  6.   --target-help            Display target specific command line options  
  7.   (Use '-v --help' to display command line options of sub-processes)  
  8.   -dumpspecs               Display all of the built in spec strings  
  9.   -dumpversion             Display the version of the compiler  
  10.   -dumpmachine             Display the compiler's target processor  
  11.   -print-search-dirs       Display the directories in the compiler's search path  
  12.   
  13.   -print-libgcc-file-name  Display the name of the compiler's companion library  
  14.   -print-file-name=<lib>   Display the full path to library <lib>  
  15.   -print-prog-name=<prog>  Display the full path to compiler component <prog>  
  16.   -print-multi-directory   Display the root directory for versions of libgcc  
  17.   -print-multi-lib         Display the mapping between command line options and  
  18.                            multiple library search directories  
  19.   -print-multi-os-directory Display the relative path to OS libraries  
  20.   -Wa,<options>            Pass comma-separated <options> on to the assembler  
  21.   -Wp,<options>            Pass comma-separated <options> on to the preprocessor  
  22.   
  23.   -Wl,<options>            Pass comma-separated <options> on to the linker  
  24.   -Xassembler <arg>        Pass <arg> on to the assembler  
  25.   -Xpreprocessor <arg>     Pass <arg> on to the preprocessor  
  26.   -Xlinker <arg>           Pass <arg> on to the linker  
  27.   -save-temps              Do not delete intermediate files  
  28.   -pipe                    Use pipes rather than intermediate files  
  29.   -time                    Time the execution of each subprocess  
  30.   -specs=<file>            Override built-in specs with the contents of <file>  
  31.   -std=<standard>          Assume that the input sources are for <standard>  
  32.   -B <directory>           Add <directory> to the compiler's search paths  
  33.   -b <machine>             Run gcc for target <machine>, if installed  
  34.   -V <version>             Run gcc version number <version>, if installed  
  35.   -v                       Display the programs invoked by the compiler  
  36.   -###                     Like -v but options quoted and commands not executed  
  37.   -E                       Preprocess only; do not compile, assemble or link  
  38.   -S                       Compile only; do not assemble or link  
  39.   -c                       Compile and assemble, but do not link  
  40.   -o <file>                Place the output into <file>  
  41.   -x <language>            Specify the language of the following input files  
  42.                            Permissible languages include: c c++ assembler none  
  43.                            'none' means revert to the default behavior of  
  44.                            guessing the language based on the file's extension  
  45.   
  46. Options starting with -g, -f, -m, -O, -W, or --param are automatically  
  47.  passed on to the various sub-processes invoked by g++.  In order to pass  
  48.  other options on to these processes the -W<letter> options must be used.  
  49.   
  50. For bug reporting instructions, please see:  
  51. <URL:http://www.mingw.org/bugs.shtml>.  
  52.   
  53. C:\>  


现在以编译 pycap为例:

1.首先下载pycap http://pypcap.googlecode.com/files/pypcap-1.1.tar.gz
2.下载wdp http://www.winpcap.org/install/bin/WpdPack_4_0_2.zip
3.解压这两个文件到同一目录,注意:要到同一目录


4.在解压后的pycap文件夹中建立一个setup.cfg文件,内容为:

Java代码   收藏代码
  1. [build]  
  2. compiler=mingw32  

5编译,如下:
Java代码   收藏代码
  1. C:\Users\zhaolei\Desktop\pypcap-1.1>python setup.py build  
  2. running build  
  3. running build_ext  
  4. building 'pcap' extension  
  5. creating build  
  6. creating build\temp.win32-2.6  
  7. creating build\temp.win32-2.6\Release  
  8. D:\program\c++\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\includ  
  9.  -ID:\program\python\python2.6\include -ID:\program\python\python2.6\PC -c pcap  
  10. c -o build\temp.win32-2.6\Release\pcap.o -DWIN32 -DWPCAP  
  11. writing build\temp.win32-2.6\Release\pcap.def  
  12. creating build\lib.win32-2.6  
  13. D:\program\c++\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.6\Re  
  14. ease\pcap.o build\temp.win32-2.6\Release\pcap_ex.o build\temp.win32-2.6\Release  
  15. pcap.def -L..\WpdPack\lib -LD:\program\python\python2.6\libs -LD:\program\pytho  
  16. \python2.6\PCbuild -lwpcap -liphlpapi -lpython26 -lmsvcr90 -o build\lib.win32-2  
  17. 6\pcap.pyd  
  18.   
  19. C:\Users\zhaolei\Desktop\pypcap-1.1>python setup.py install  


5 .利用同样的方法安装sendpkt
6.测试
Java代码   收藏代码
  1. C:\Users\zhaolei>python  
  2. Python 2.6 (r26:66721, Oct  2 200811:35:03) [MSC v.1500 32 bit (Intel)] on win  
  3. 32  
  4. Type "help""copyright""credits" or "license" for more information.  
  5. >>> import pcap,sendpkt,dpkt  
  6. >>>  

————————————————————

python27上验证通过,python34需要添加额外模块,没有继续测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值