免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3115 | 回复: 1
打印 上一主题 下一主题

python2.6(windows 7)下安装pycap、sendpkt、dpkt [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-20 14:21 |只看该作者 |倒序浏览
我的系统是window7、python2.6。pycap和sendpkt结合起来做网络抓包分析非常好,可惜google code上提供的都是针对python2.5的,我的是python2.6,没有办法,只好自己去编译。

编译采用mingw编译,可以到http://www.mingw.org/上去下载,下载后安装然后添加安装路径到环境变量,看到如下效果即可:
  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.   -print-libgcc-file-name  Display the name of the compiler's companion library
  13.   -print-file-name=<lib>   Display the full path to library <lib>
  14.   -print-prog-name=<prog>  Display the full path to compiler component <prog>
  15.   -print-multi-directory   Display the root directory for versions of libgcc
  16.   -print-multi-lib         Display the mapping between command line options and
  17.                            multiple library search directories
  18.   -print-multi-os-directory Display the relative path to OS libraries
  19.   -Wa,<options>            Pass comma-separated <options> on to the assembler
  20.   -Wp,<options>            Pass comma-separated <options> on to the preprocessor

  21.   -Wl,<options>            Pass comma-separated <options> on to the linker
  22.   -Xassembler <arg>        Pass <arg> on to the assembler
  23.   -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  24.   -Xlinker <arg>           Pass <arg> on to the linker
  25.   -save-temps              Do not delete intermediate files
  26.   -pipe                    Use pipes rather than intermediate files
  27.   -time                    Time the execution of each subprocess
  28.   -specs=<file>            Override built-in specs with the contents of <file>
  29.   -std=<standard>          Assume that the input sources are for <standard>
  30.   -B <directory>           Add <directory> to the compiler's search paths
  31.   -b <machine>             Run gcc for target <machine>, if installed
  32.   -V <version>             Run gcc version number <version>, if installed
  33.   -v                       Display the programs invoked by the compiler
  34.   -###                     Like -v but options quoted and commands not executed
  35.   -E                       Preprocess only; do not compile, assemble or link
  36.   -S                       Compile only; do not assemble or link
  37.   -c                       Compile and assemble, but do not link
  38.   -o <file>                Place the output into <file>
  39.   -x <language>            Specify the language of the following input files
  40.                            Permissible languages include: c c++ assembler none
  41.                            'none' means revert to the default behavior of
  42.                            guessing the language based on the file's extension

  43. Options starting with -g, -f, -m, -O, -W, or --param are automatically
  44. passed on to the various sub-processes invoked by g++.  In order to pass
  45. other options on to these processes the -W<letter> options must be used.

  46. For bug reporting instructions, please see:
  47. <URL:http://www.mingw.org/bugs.shtml>.

  48. 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文件,内容为:
  1. [build]
  2. compiler=mingw32
复制代码
5编译,如下:

  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. C:\Users\zhaolei\Desktop\pypcap-1.1>python setup.py install
复制代码
5.利用同样的方法安装sendpkt
6.测试
  1. C:\Users\zhaolei>python
  2. Python 2.6 (r26:66721, Oct  2 2008, 11: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. >>>
复制代码
可以Build了,
如下:
  1. C:\Documents and Settings\xeme\桌面\pcap_build\pypcap-1.1>setup.py build
  2. running build
  3. running build_ext
  4. building 'pcap' extension
  5. creating build
  6. creating build\temp.win32-2.5
  7. creating build\temp.win32-2.5\Release
  8. d:\GNUstep\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\include -ID:\Python25\include -ID:\Python25\PC -c p
  9. cap.c -o build\temp.win32-2.5\Release\pcap.o -DWIN32 -DWPCAP
  10. pcap.c: In function `__pyx_f_4pcap_3bpf___dealloc__':
  11. pcap.c:320: warning: label `__pyx_L1' defined but not used
  12. pcap.c: In function `__pyx_f_4pcap_4pcap_dispatch':
  13. pcap.c:1039: warning: passing arg 3 of `pcap_dispatch' from incompatible pointer type
  14. pcap.c: In function `__pyx_f_4pcap_4pcap_loop':
  15. pcap.c:1142: warning: passing arg 3 of `pcap_ex_next' from incompatible pointer type
  16. pcap.c:1134: warning: label `__pyx_L2' defined but not used
  17. pcap.c: In function `__pyx_f_4pcap_4pcap___iter__':
  18. pcap.c:1305: warning: label `__pyx_L1' defined but not used
  19. pcap.c: In function `__pyx_f_4pcap_4pcap___next__':
  20. pcap.c:1338: warning: passing arg 3 of `pcap_ex_next' from incompatible pointer type
  21. pcap.c:1330: warning: label `__pyx_L2' defined but not used
  22. pcap.c:1382: warning: label `__pyx_L3' defined but not used
  23. pcap.c: In function `__pyx_f_4pcap_4pcap___dealloc__':
  24. pcap.c:1433: warning: label `__pyx_L1' defined but not used
  25. pcap.c: In function `__pyx_tp_new_4pcap_bpf':
  26. pcap.c:1567: warning: unused variable `p'
  27. pcap.c: In function `__pyx_tp_dealloc_4pcap_bpf':
  28. pcap.c:1572: warning: unused variable `p'
  29. pcap.c: In function `__pyx_tp_traverse_4pcap_bpf':
  30. pcap.c:1586: warning: unused variable `e'
  31. pcap.c:1587: warning: unused variable `p'
  32. pcap.c: In function `__pyx_tp_clear_4pcap_bpf':
  33. pcap.c:1592: warning: unused variable `p'
  34. pcap.c: In function `__pyx_tp_new_4pcap_pcap':
  35. pcap.c:1719: warning: unused variable `p'
  36. pcap.c: In function `__pyx_tp_dealloc_4pcap_pcap':
  37. pcap.c:1724: warning: unused variable `p'
  38. pcap.c: In function `__pyx_tp_traverse_4pcap_pcap':
  39. pcap.c:1738: warning: unused variable `e'
  40. pcap.c:1739: warning: unused variable `p'
  41. pcap.c: In function `__pyx_tp_clear_4pcap_pcap':
  42. pcap.c:1744: warning: unused variable `p'
  43. pcap.c: In function `__Pyx_GetStarArgs':
  44. pcap.c:2253: warning: suggest explicit braces to avoid ambiguous `else'
  45. pcap.c:2255: warning: suggest explicit braces to avoid ambiguous `else'
  46. pcap.c: At top level:
  47. pcap.c:14: warning: '__Pyx_UnpackItem' declared `static' but never defined
  48. pcap.c:15: warning: '__Pyx_EndUnpack' declared `static' but never defined
  49. pcap.c:16: warning: '__Pyx_PrintItem' declared `static' but never defined
  50. pcap.c:17: warning: '__Pyx_PrintNewline' declared `static' but never defined
  51. pcap.c:19: warning: '__Pyx_ReRaise' declared `static' but never defined
  52. pcap.c:22: warning: '__Pyx_ArgTypeTest' declared `static' but never defined
  53. pcap.c:23: warning: '__Pyx_TypeTest' declared `static' but never defined
  54. pcap.c:27: warning: '__Pyx_ImportType' declared `static' but never defined
  55. pcap.c:28: warning: '__Pyx_SetVtable' declared `static' but never defined
  56. pcap.c:29: warning: '__Pyx_GetVtable' declared `static' but never defined
  57. pcap.c:30: warning: '__Pyx_CreateClass' declared `static' but never defined
  58. d:\GNUstep\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\include -ID:\Python25\include -ID:\Python25\PC -c p
  59. cap_ex.c -o build\temp.win32-2.5\Release\pcap_ex.o -DWIN32 -DWPCAP
  60. pcap_ex.c: In function `pcap_ex_next':
  61. pcap_ex.c:235: warning: passing arg 3 of `pcap_next_ex' from incompatible pointer type
  62. writing build\temp.win32-2.5\Release\pcap.def
  63. creating build\lib.win32-2.5
  64. d:\GNUstep\mingw\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.5\Release\pcap.o build\temp.win32-2.5\Release\pca
  65. p_ex.o build\temp.win32-2.5\Release\pcap.def -L..\WpdPack\lib -LD:\Python25\libs -LD:\Python25\PCBuild -lwpcap -liphlpap
  66. i -lpython25 -lmsvcr71 -o build\lib.win32-2.5\pcap.pyd

  67. C:\Documents and Settings\xeme\桌面\pcap_build\pypcap-1.1>
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-04-20 14:40 |只看该作者
顶一下,好东西
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP