目录

PyStun3 库简介

Installation 安装

Usage 用法

PyNAT 库简介

Installation 安装

From PyPI 来自 PyPI

From GitHub 来自 GitHub

Usage 用法


PyStun3 库简介

官网地址:官网地址:https://github.com/talkiq/pystun3

Installation 安装

To install the latest version:

安装最新版本:

$ pip install pystun3

or download/clone the source and install manually using:

或下载/复制源代码,并使用以下方法手动安装:

$ cd /path/to/pystun3/src
$ python setup.py install

If you're hacking on pystun3 you should use the 'develop' command instead:

如果你正在使用 pystun3,你应该使用‘ develop’命令:

$ python setup.py develop

This will make a link to the sources inside your site-packages directory so that any changes are immediately available for testing.

这将为站点包目录中的源创建一个链接,这样任何更改都可以立即进行测试。

Usage 用法

From command line:

从命令行:

$ pystun3
NAT Type: Full Cone
External IP: <your-ip-here>
External Port: 54320

Pass --help for more options:

通过---- 更多选项的帮助:

% pystun3 --help
usage: pystun3 [-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_HOSTSTUN host to use (default: None)-P STUN_PORT, --host-port STUN_PORTSTUN host port to use (default: 3478)-i SOURCE_IP, --interface SOURCE_IPnetwork interface for client (default: 0.0.0.0)-p SOURCE_PORT, --port SOURCE_PORTport to listen on for client (default: 54320)--version             show program's version number and exit

From Python:

来自 Python:

import stun
nat_type, external_ip, external_port = stun.get_ip_info()

This will rotate through an internal list of STUN servers until a response is found. If no response is found you will get "Blocked" as the nat_type and None for external_ip and external_port.

这将通过 STUN 服务器的内部列表循环,直到找到响应。如果没有找到响应,您将得到“ Blocked”作为 nat _ type,而 None 作为 external _ ip 和 external _ port。

If you prefer to use a specific STUN server:

如果您喜欢使用特定的 STUN 服务器:

nat_type, external_ip, external_port = stun.get_ip_info(stun_host='stun.ekiga.net')

If you prefer to use a specific STUN server port:

如果您喜欢使用特定的 STUN 服务器端口:

nat_type, external_ip, external_port = stun.get_ip_info(stun_port=3478)

You may also specify the client interface and port that is used although this is not needed:

您还可以指定使用的客户端接口和端口,尽管不需要这样做:

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)

PyNAT 库简介

官网地址:https://github.com/aarant/pynat

Discover external IP addresses and NAT topologies using STUN (Simple Traversal of UDP Through Network Address Translators).

使用 STUN (通过网络地址转换器的 UDP 简单遍历)发现外部 IP 地址和 NAT 拓扑。

PyNAT follows RFC 3489, and is inspired by a similar program for Python 2.x called PyStun. PyNAT supports Python 2.7 and later.

遵循 RFC 3489,灵感来自 Python 2. x 的一个类似程序 PyStun。支持 Python 2.7及更高版本。

Installation 安装

PyNAT requires Python 2.7 or later.

需要 Python 2.7或更高版本。

From PyPI 来自 PyPI

Install PyNAT by running pip3 install pynat from the command line.

通过从命令行运行 pip3 Install PyNAT 来安装 PyNAT。

Note

注意

On some Linux systems, installation may require running pip with root permissions, or running pip3 install pynat --user. The latter may require exporting ~/.local/bin to PATH.

在某些 Linux 系统上,安装可能需要使用 root 权限运行 pip,或者运行 pip3 install pynat -- user。后者可能需要出口。本地/垃圾桶到 PATH。

From GitHub 来自 GitHub

Clone or download the git repo, navigate to the directory, and run:

克隆或下载 git repo,导航到目录,然后运行:

python3 setup.py sdist
cd dist
pip3 install pynat-<version>.tar.gz

Usage 用法

To get information about the network topology and external IP/port used, run pynat:

要获取有关网络拓扑和所使用的外部 IP/端口的信息,运行 pynat:

Network type: UDP Firewall
Internal address: 127.0.0.1:54320
External address: 127.0.0.1:54320

Run pynat -h or pynat --help for more options:

运行 pynat-h 或 pynat-help for more options:

usage: pynat [-h] [--source_ip SOURCE_IP] [--source-port SOURCE_PORT][--stun-host STUN_HOST] [--stun-port STUN_PORT]PyNAT v0.0.0 Discover external IP addresses and NAT topologies using STUN.
Copyright (C) 2018 Ariel Antonitis. Licensed under the MIT License.optional arguments:-h, --help            show this help message and exit--source_ip SOURCE_IPThe source IPv4 address to bind to.--source-port SOURCE_PORTThe source port to bind to.--stun-host STUN_HOSTThe STUN host to use for queries.--stun-port STUN_PORTThe port of the STUN host to use for queries.

To use PyNAT inside a Python shell or project:

在 Python shell 或者项目中使用 PyNAT:

from pynat import get_ip_info
topology, ext_ip, ext_port = get_ip_info()

To also get information about the internal IP, if unknown:

还可以获取内部 IP 的信息,如果不知道:

topology, ext_ip, ext_port, int_ip = get_ip_info(include_internal=True)

python3 获取nat类型和外部ip PyStun3 PyNAT 库简介相关推荐

  1. python3 获取异常类型

    方法一:repr import jsondef austin():try:json_data = ""json.loads(json_data)except Exception a ...

  2. Linux设备检测外部网络NAT类型

    Linux设备检测外部网络NAT类型 在异地组网的过程中发现,对称型NAT(Symmetric NAT)对P2P穿透的支持很不好,因此在搭建P2P穿透个人使用的客户端或服务器之前有必要搞清楚自己所在网 ...

  3. NAT类型及打洞原理

    NAT是Network Address Translation的缩写,指的是主机地址与公网IP的映射规则:就是说比如你有一个pc,连到局域网,然后你要访问163.com,这时候局域网会你的ip和打开的 ...

  4. golang中获取公网ip、查看内网ip、检测ip类型、校验ip区间、ip地址string和int转换、根据ip判断地区国家运营商等

    作者: 一蓑烟雨1989 所属专栏: Go从不放弃到实战 本文链接:https://blog.csdn.net/wangshubo1989/article/details/78066344 生命不止, ...

  5. P2P穿透四种NAT类型

    P2P穿透&四种NAT类型 以下对四种NAT类型分别予以说明: 1.全锥形NAT IP.端口都不受限.只要客户端由内到外打通一个洞之后(NatIP:NatPort -> A:P1),其他 ...

  6. NAT类型和打洞流程

    一.NAT 1. 含义 NAT技术(Network Address Translation,网络地址转换)是一种把内部网络(简称为内网)私有IP地址转换为外部网络(简称为外网)公共IP地址的技术,它使 ...

  7. NAT类型、探测及穿透

    NAT总结比较全面参考:第五期(NAT专题)-新华三集团-H3C 1.NAT类型 1.1 NAT类型及分布统计 基本NAT,只做内网IP与公网IP的替换,网络层以上的部分不替换,即端口不变. 静态地址 ...

  8. STUN协议和常用NAT类型

    文章目录 Nat的基本原理 Nat的优缺点 Nat的3种形态 1.静态NAT (一对一) 2.动态NAT (多对多) 3.端口多路复用(多对一,目前使用最多的) NATP类型的分类 (1)全锥型(Fu ...

  9. NAT类型及检测方法

    一 NAT的类型 NAT可以分为很多种,但是最为普遍的是传统NAT,或者称为向外NAT.向外NAT在默认情况下只允许向外的Session穿越NAT,这就是我们最为常见的情况. 这种向外NAT又可以分为 ...

最新文章

  1. 在Ubuntu 14.04 64bit上安装Master PDF Editor 3.2.81
  2. 小米今日正式进军越南市场 借助合作方铺渠道分销
  3. 目标检测(Object Detection)原理与实现
  4. Spring SpringMVC SpringBoot SpringCloud概念、关系及区别
  5. Java格式化Date为字符串的高级写法
  6. 将数据库日志添加到JUnit3
  7. Linux驱动开发中与设备树相关的6种debug方法
  8. 数据流被污染?数据质量不高?蚂蚁金服数据资产管理平台了解一下
  9. 风过处,纷纷下落的黄叶
  10. 高性能服务器中的C10K问题
  11. 论文笔记_S2D.41_2017-ICCV-使用深度估计与深度卷积神经场,进行单目视觉里程计的尺度恢复
  12. 深度学习 检测异常_深度学习用于异常检测:全面调查
  13. 华为路由器配置OSPF实例
  14. 如何不用u盘将32位Windows转为64位Windows
  15. table2excel 导出表格有边框,文字居中
  16. php json输出后 u6563,肉肉's Blog
  17. ATFX:非农就业报告来袭,美元指数或再迎剧烈波动
  18. 网站使用QQ互联接入第三方登录,实现qq快捷登录网站的功能
  19. 蒙特卡洛之布丰投针(python实现)
  20. 保研保专硕计算机专业,如果保研只能保专硕,是否应该放弃保研自己考?

热门文章

  1. TVS管 具体原理和作用
  2. Fortran学习记录1(Fortran数据类型)
  3. 【luogu 3397】地毯 差分
  4. 一个成功人士的创业心得
  5. js分享到微信朋友圈、QQ空间、QQ好友、新浪微博、腾讯微博、豆瓣、人人......
  6. c51单片机c语言取反运算符,单片机c语言教程:C51运算符和表达式
  7. Nginx 指定域名(或子域名)和网站绑定
  8. [水晶报表]水晶报表数据库登陆问题
  9. 风控模型中的KS指标
  10. FTP服务器的上传与下载