TCP端口监视和发现

portend的Python项目详细描述


https://img.shields.io/pypi/v/portend.svghttps://img.shields.io/pypi/pyversions/portend.svghttps://img.shields.io/travis/jaraco/portend/master.svgCode style: Blackhttps://img.shields.io/appveyor/ci/jaraco/portend/master.svghttps://readthedocs.org/projects/portend/badge/?version=latest

波尔·坦德 倾向/ 动词

be a sign or warning that (something, especially something momentous or calamitous) is likely to happen.

用法

使用portend监视TCP端口的绑定或未绑定状态。

例如,要等待端口被占用,请在3秒后超时:

portend.occupied('www.google.com', 80, timeout=3)

或等待端口空闲,5秒后超时:

portend.free('::1', 80, timeout=5)

端口也可以直接执行。如果函数成功,则 返回任何状态,退出状态为0。如果失败了,它会打印一个 具有1状态的消息和出口。例如:

python -m portend localhost:31923 free
(exits immediately)

python -m portend -t 1 localhost:31923 occupied
(one second passes)
Port 31923 not bound on localhost.

portend还公开了用于标识的find_available_local_port。 适合本地绑定的端口:

port = portend.find_available_local_port()
print(port, "is available for binding")

portend还公开了低级端口检查功能 在Checker类中,该类当前只公开一个public 方法,assert_free

portend.Checker().assert_free('localhost', 31923)

如果assert_free被传递一个被占用的主机/端口组合 绑定侦听器(即建立到该主机/端口的TCP连接); assert_free将引发PortNotFree异常。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无JPA的纯Hibernate ORM java SpringBoot配置   安卓会生成一组唯一的java数字   java我的自定义阵列列表每次启动时都会崩溃我不确定为什么会一直崩溃   Java继承;将子类传递给超类的抽象方法   java从没有if语句的数组中获取instanceof type   java中使用对象的温度转换   存储库接口的JavaSpringDataMongoDBeanXML配置   java JAXWS为iBM websphere、iBM web服务客户端添加寻址   数组试图返回Java中两个对象的面积之和   apache Spark java:columnNameOfCorruptRecord和badRecordsPath在加载csv时不工作   java无法创建。txt文件   java Hibernate与MySQL插入查询不一致   不考虑java Hazelcast分布式地图的最大大小   bash Java如何在父进程中设置环境变量