- 论坛徽章:
- 0
|
我的系统是window7、python2.6。pycap和sendpkt结合起来做网络抓包分析非常好,可惜google code上提供的都是针对python2.5的,我的是python2.6,没有办法,只好自己去编译。
编译采用mingw编译,可以到http://www.mingw.org/上去下载,下载后安装然后添加安装路径到环境变量,看到如下效果即可:- C:\>g++ --help
- Usage: g++ [options] file...
- Options:
- -pass-exit-codes Exit with highest error code from a phase
- --help Display this information
- --target-help Display target specific command line options
- (Use '-v --help' to display command line options of sub-processes)
- -dumpspecs Display all of the built in spec strings
- -dumpversion Display the version of the compiler
- -dumpmachine Display the compiler's target processor
- -print-search-dirs Display the directories in the compiler's search path
- -print-libgcc-file-name Display the name of the compiler's companion library
- -print-file-name=<lib> Display the full path to library <lib>
- -print-prog-name=<prog> Display the full path to compiler component <prog>
- -print-multi-directory Display the root directory for versions of libgcc
- -print-multi-lib Display the mapping between command line options and
- multiple library search directories
- -print-multi-os-directory Display the relative path to OS libraries
- -Wa,<options> Pass comma-separated <options> on to the assembler
- -Wp,<options> Pass comma-separated <options> on to the preprocessor
- -Wl,<options> Pass comma-separated <options> on to the linker
- -Xassembler <arg> Pass <arg> on to the assembler
- -Xpreprocessor <arg> Pass <arg> on to the preprocessor
- -Xlinker <arg> Pass <arg> on to the linker
- -save-temps Do not delete intermediate files
- -pipe Use pipes rather than intermediate files
- -time Time the execution of each subprocess
- -specs=<file> Override built-in specs with the contents of <file>
- -std=<standard> Assume that the input sources are for <standard>
- -B <directory> Add <directory> to the compiler's search paths
- -b <machine> Run gcc for target <machine>, if installed
- -V <version> Run gcc version number <version>, if installed
- -v Display the programs invoked by the compiler
- -### Like -v but options quoted and commands not executed
- -E Preprocess only; do not compile, assemble or link
- -S Compile only; do not assemble or link
- -c Compile and assemble, but do not link
- -o <file> Place the output into <file>
- -x <language> Specify the language of the following input files
- Permissible languages include: c c++ assembler none
- 'none' means revert to the default behavior of
- guessing the language based on the file's extension
- Options starting with -g, -f, -m, -O, -W, or --param are automatically
- passed on to the various sub-processes invoked by g++. In order to pass
- other options on to these processes the -W<letter> options must be used.
- For bug reporting instructions, please see:
- <URL:http://www.mingw.org/bugs.shtml>.
- 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文件,内容为:5编译,如下:
- C:\Users\zhaolei\Desktop\pypcap-1.1>python setup.py build
- running build
- running build_ext
- building 'pcap' extension
- creating build
- creating build\temp.win32-2.6
- creating build\temp.win32-2.6\Release
- D:\program\c++\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\includ
- -ID:\program\python\python2.6\include -ID:\program\python\python2.6\PC -c pcap
- c -o build\temp.win32-2.6\Release\pcap.o -DWIN32 -DWPCAP
- writing build\temp.win32-2.6\Release\pcap.def
- creating build\lib.win32-2.6
- D:\program\c++\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.6\Re
- ease\pcap.o build\temp.win32-2.6\Release\pcap_ex.o build\temp.win32-2.6\Release
- pcap.def -L..\WpdPack\lib -LD:\program\python\python2.6\libs -LD:\program\pytho
- \python2.6\PCbuild -lwpcap -liphlpapi -lpython26 -lmsvcr90 -o build\lib.win32-2
- 6\pcap.pyd
- C:\Users\zhaolei\Desktop\pypcap-1.1>python setup.py install
复制代码 5.利用同样的方法安装sendpkt
6.测试- C:\Users\zhaolei>python
- Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win
- 32
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import pcap,sendpkt,dpkt
- >>>
复制代码 可以Build了,
如下:- C:\Documents and Settings\xeme\桌面\pcap_build\pypcap-1.1>setup.py build
- running build
- running build_ext
- building 'pcap' extension
- creating build
- creating build\temp.win32-2.5
- creating build\temp.win32-2.5\Release
- d:\GNUstep\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\include -ID:\Python25\include -ID:\Python25\PC -c p
- cap.c -o build\temp.win32-2.5\Release\pcap.o -DWIN32 -DWPCAP
- pcap.c: In function `__pyx_f_4pcap_3bpf___dealloc__':
- pcap.c:320: warning: label `__pyx_L1' defined but not used
- pcap.c: In function `__pyx_f_4pcap_4pcap_dispatch':
- pcap.c:1039: warning: passing arg 3 of `pcap_dispatch' from incompatible pointer type
- pcap.c: In function `__pyx_f_4pcap_4pcap_loop':
- pcap.c:1142: warning: passing arg 3 of `pcap_ex_next' from incompatible pointer type
- pcap.c:1134: warning: label `__pyx_L2' defined but not used
- pcap.c: In function `__pyx_f_4pcap_4pcap___iter__':
- pcap.c:1305: warning: label `__pyx_L1' defined but not used
- pcap.c: In function `__pyx_f_4pcap_4pcap___next__':
- pcap.c:1338: warning: passing arg 3 of `pcap_ex_next' from incompatible pointer type
- pcap.c:1330: warning: label `__pyx_L2' defined but not used
- pcap.c:1382: warning: label `__pyx_L3' defined but not used
- pcap.c: In function `__pyx_f_4pcap_4pcap___dealloc__':
- pcap.c:1433: warning: label `__pyx_L1' defined but not used
- pcap.c: In function `__pyx_tp_new_4pcap_bpf':
- pcap.c:1567: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_dealloc_4pcap_bpf':
- pcap.c:1572: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_traverse_4pcap_bpf':
- pcap.c:1586: warning: unused variable `e'
- pcap.c:1587: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_clear_4pcap_bpf':
- pcap.c:1592: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_new_4pcap_pcap':
- pcap.c:1719: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_dealloc_4pcap_pcap':
- pcap.c:1724: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_traverse_4pcap_pcap':
- pcap.c:1738: warning: unused variable `e'
- pcap.c:1739: warning: unused variable `p'
- pcap.c: In function `__pyx_tp_clear_4pcap_pcap':
- pcap.c:1744: warning: unused variable `p'
- pcap.c: In function `__Pyx_GetStarArgs':
- pcap.c:2253: warning: suggest explicit braces to avoid ambiguous `else'
- pcap.c:2255: warning: suggest explicit braces to avoid ambiguous `else'
- pcap.c: At top level:
- pcap.c:14: warning: '__Pyx_UnpackItem' declared `static' but never defined
- pcap.c:15: warning: '__Pyx_EndUnpack' declared `static' but never defined
- pcap.c:16: warning: '__Pyx_PrintItem' declared `static' but never defined
- pcap.c:17: warning: '__Pyx_PrintNewline' declared `static' but never defined
- pcap.c:19: warning: '__Pyx_ReRaise' declared `static' but never defined
- pcap.c:22: warning: '__Pyx_ArgTypeTest' declared `static' but never defined
- pcap.c:23: warning: '__Pyx_TypeTest' declared `static' but never defined
- pcap.c:27: warning: '__Pyx_ImportType' declared `static' but never defined
- pcap.c:28: warning: '__Pyx_SetVtable' declared `static' but never defined
- pcap.c:29: warning: '__Pyx_GetVtable' declared `static' but never defined
- pcap.c:30: warning: '__Pyx_CreateClass' declared `static' but never defined
- d:\GNUstep\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -I..\WpdPack\include -ID:\Python25\include -ID:\Python25\PC -c p
- cap_ex.c -o build\temp.win32-2.5\Release\pcap_ex.o -DWIN32 -DWPCAP
- pcap_ex.c: In function `pcap_ex_next':
- pcap_ex.c:235: warning: passing arg 3 of `pcap_next_ex' from incompatible pointer type
- writing build\temp.win32-2.5\Release\pcap.def
- creating build\lib.win32-2.5
- 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
- p_ex.o build\temp.win32-2.5\Release\pcap.def -L..\WpdPack\lib -LD:\Python25\libs -LD:\Python25\PCBuild -lwpcap -liphlpap
- i -lpython25 -lmsvcr71 -o build\lib.win32-2.5\pcap.pyd
- C:\Documents and Settings\xeme\桌面\pcap_build\pypcap-1.1>
复制代码 |
|