使用asyncio的upnp操作的python库

pyupnp-async的Python项目详细描述


使用asyncio的upnp操作的python库。

目前,这个库只为使用upnp进行端口转发提供了方便。对于其他upnp特性,它是 可能,但需要手动构造请求参数。(即soup请求xml。)

安装

要安装最新的开发版本,请运行:

git clone https://github.com/xinhuang/pyupnp-async.git
cd pyupnp-async
python setup.py install

此包不在pypi上。

快速教程

使用upnp创建端口转发:

frompyupnp_asyncimportmsearch_firstasyncdefforward_port(local_ip,local_port,ext_port,protocol):resp=awaitmsearch_first('urn:schemas-upnp-org:device:InternetGatewayDevice:1')device=awaitresp.get_device()service=device.find_first_service('urn:schemas-upnp-org:service:WANIPConnection:1')ext_ip=awaitservice.get_external_ip_address()try:awaitservice.add_port_mapping(local_port,ext_port,local_ip,protocol)print('Data to external Port {} will be forwarded to {}:{}'.format(ext_port,local_ip,local_port))exceptUpnpSoapErrorase:print(e)

使用upnp删除端口转发:

frompyupnp_asyncimportmsearch_firstasyncdefstop_forwarding(ext_port,protocol):resp=awaitmsearch_first('urn:schemas-upnp-org:device:InternetGatewayDevice:1')device=awaitresp.get_device()service=device.find_first_service('urn:schemas-upnp-org:service:WANIPConnection:1')ext_ip=awaitservice.get_external_ip_address()try:awaitservice.delete_port_mapping(ext_port,protocol)print('Data to external Port {} will not be forwarded any more.')exceptUpnpSoapErrorase:print(e)

API参考

msearch_first(search_target='upnp:rootdevice', max_wait=2, loop=None)

搜索指定的upnp目标,并返回第一个响应的目标。

Args:
  • ^{tt2}$: Search target. For details please reference to UPnP spec.
  • ^{tt3}$: Specify max waiting time in seconds.
  • ^{tt4}$: Specify the event loop to be used. Default is ^{tt5}$

msearch_first(search_target='upnp:rootdevice', max_wait=2, loop=None)

搜索指定的upnp目标,并以异步迭代器的形式返回给定时间范围内响应的所有目标。

Args:
  • ^{tt2}$: Search target. For details please reference to UPnP spec.
  • ^{tt3}$: Specify max waiting time in seconds.
  • ^{tt4}$: Specify the event loop to be used. Default is ^{tt5}$

许可

这个项目是根据麻省理工学院开放源码许可证的条款发布的。查看 license.txt了解更多信息。

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

推荐PyPI第三方库


热门话题
java如何使用JNA创建同一库的多个实例?   java在将Graphql查询作为JSON字符串传递时收到意外的令牌错误   OAuth2 oltu的java问题   java桌面应用程序使用的好的嵌入式数据库是什么?   java Firebase数据库高级查询选项   java正在使磁盘上的EhCache元素过期   java 安卓还原处于backstack中的片段的实例状态   XMemcached中的java异步集   java TimescaleDB是否使用与Postgresql完全相同的JDBC驱动程序?   java从网站c读取信息#   检查java Android中的字符串是否只包含数字和空格   c#如何向web服务发送特殊字符?   grails无法调用需要java的方法。lang.类参数?   java我在组合框中调用的方法不会运行所有代码,它只运行部分代码   java发送带有标头的HTTP GET请求