python stun客户端,用于获取nat类型和外部ip(rfc 3489)
pystun的Python项目详细描述
Pystun
python stun客户端,用于获取nat类型和外部ip
这是一个由高鹰(http://code.google.com/p/pystun/)最初创建的pystun叉
Pystun遵循RFC 3489:http://www.ietf.org/rfc/rfc3489.txt
在Internet上找不到跟踪stun bis的服务器,因此rfc3489是 只有执行。
安装
要安装最新版本:
$ pip install pystun
或下载/克隆源并使用以下命令手动安装:
$ cd /path/to/pystun/src $ python setup.py install
如果您正在对pystun进行黑客攻击,则应改用“develop”命令:
$ python setup.py develop
这将链接到站点包目录中的源,以便 任何更改都可以立即进行测试。
使用量
从命令行:
$ pystun NAT Type: Full Cone External IP: <your-ip-here> External Port: 54320
通过–更多选项的帮助:
% pystun --help usage: pystun [-h] [-d] [-H STUN_HOST] [-P STUN_PORT] [-i SOURCE_IP] [-p SOURCE_PORT] [--version] optional arguments: -h, --help show this help message and exit -d, --debug Enable debug logging (default: False) -H STUN_HOST, --host STUN_HOST STUN host to use (default: None) -P STUN_PORT, --host-port STUN_PORT STUN host port to use (default: 3478) -i SOURCE_IP, --interface SOURCE_IP network interface for client (default: 0.0.0.0) -p SOURCE_PORT, --port SOURCE_PORT port to listen on for client (default: 54320) --version show program's version number and exit
来自python:
import stun nat_type, external_ip, external_port = stun.get_ip_info()
这将在stun服务器的内部列表中循环,直到响应为 找到了。如果没有找到响应,您将被“阻塞”为nat_type并且 none对于external_ip和external_port。
如果您喜欢使用特定的stun服务器:
nat_type, external_ip, external_port = stun.get_ip_info(stun_host='stun.ekiga.net')
如果您喜欢使用特定的stun服务器端口:
nat_type, external_ip, external_port = stun.get_ip_info(stun_port=3478)
您还可以指定使用的客户机接口和端口,尽管 不需要:
sip = "0.0.0.0" # interface to listen on (all) port = 54320 # port to listen on nat_type, external_ip, external_port = stun.get_ip_info(sip, port)
阅读代码了解更多详细信息…
许可证
麻省理工学院