how to embed C code in python program?

谁说我不能喝 提交于 2019-12-10 16:33:12

问题


i want to write a program using multi-threading, raw sockets, to scan the ports in python i have a C code for injection of raw socket. i want to perform a ACK scan so need a raw socket.

So please help me.

thank you


回答1:


Please check out Cython. It makes it very easy to wrap C code.

This is adapted from the documentation on calling external C functions:

cdef extern from "math.h":
    double sin(double)

def pysin(x):
    return sin(x)

You could then call pysin from the compiled module like a normal Python module.




回答2:


I would definitely go with boost.python, which provides even cleaner wrappers. If you dislike the idea of using C++, then Cython is a good alternative.



来源:https://stackoverflow.com/questions/3968499/how-to-embed-c-code-in-python-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!