跳转到主要内容

Linux Tun/Tap设备的面向对象包装器

项目描述

https://github.com/johnthagen/pytap2/workflows/python/badge.svg https://codeclimate.com/github/johnthagen/pytap2/badges/gpa.svg https://codeclimate.com/github/johnthagen/pytap2/badges/issue_count.svg https://codecov.io/github/johnthagen/pytap2/coverage.svg https://img.shields.io/pypi/v/pytap2.svg https://img.shields.io/pypi/status/pytap2.svg https://img.shields.io/pypi/pyversions/pytap2.svg

Fork of PyTap that supports Python 3.

需求

为了使 pytap2 正常运行,必须安装 ifconfig 命令行工具。

在 Debian/Ubuntu 上安装 ifconfig

$ sudo apt install net-tools

在 RHEL/Rocky Linux/Fedora 上安装 ifconfig

$ sudo yum install net-tools

安装

您可以使用以下命令安装、升级和卸载 pytap2

$ pip install pytap2
$ pip install --upgrade pytap2
$ pip uninstall pytap2

用法

作为上下文管理器使用会自动在 with 块结束时打开设备并关闭它。

from pytap2 import TapDevice

with TapDevice() as device:
    device.ifconfig(mtu=1300)
    device.write(b'0000')

或者手动调用 up()close()

from pytap2 import TapDevice

device = TapDevice()
device.up()
device.ifconfig(mtu=1300)
device.write(b'0000')
device.close()

定义了 fileno() 方法,因此可以将设备对象直接传递到 select()

版本

2.3.0 - 2023-04-28

  • 弃用 Python 3.7,支持 Python 3.11

  • 支持用户进行 Mypy 类型检查

2.2.0 - 2021-11-06

  • 弃用 Python 3.6,支持 Python 3.10。

  • 文档依赖 ifconfig

2.1.0 - 2020-12-30

  • 弃用 Python 3.5,支持 Python 3.9。

  • 切换到 GitHub Actions 进行 CI。

2.0.0 - 2020-03-29

  • 弃用 Python 2.7。

1.6.0 - 2019-12-15

  • 弃用 Python 3.4,支持 Python 3.8。

  • 包含许可证文件。

1.5.0 - 2018-07-09

支持 Python 3.7。

1.4.0 - 2017-10-24

允许禁用数据包信息头(IFF_NO_PI)并将默认的 read() 调用扩展为读取整个MTU大小的数据,如果存在则包括数据包信息头。

1.3.0 - 2017-07-31

添加了 fileno() 方法以支持 select() 调用。

1.2.0 - 2017-06-19

增加了上下文管理器支持。

1.1.0 - 2017-06-17

允许以特定字节数调用 read()

1.0.0 - 2017-06-16

这是支持Python 2和3的初始版本。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

pytap2-2.3.0.tar.gz (6.3 kB 查看哈希值)

上传时间 源代码

构建分发

pytap2-2.3.0-py3-none-any.whl (5.8 kB 查看哈希值)

上传时间 Python 3

支持者