Skip to main content

一个实用的网络工具包,提供各种网络相关的功能

Project description

Net Utils KY

一个实用的 Python 网络工具包,提供各种网络相关的功能。

功能特性

  • 🔗 HTTP 请求工具
  • 🌐 网络连接检测
  • 📡 端口扫描
  • 🔍 DNS 查询
  • 📊 网络状态监控
  • 🛡️ 代理支持
  • ⚡ 异步支持

安装

pip install net_utils_ky

快速开始

基本使用

from net_utils_ky import NetworkUtils

# 创建网络工具实例
net_utils = NetworkUtils()

# 检查网络连接
if net_utils.is_connected():
    print("网络连接正常")

# 发送HTTP请求
response = net_utils.get("https://api.github.com")
print(f"状态码: {response.status_code}")
print(f"响应内容: {response.text[:100]}...")

命令行使用

# 检查网络连接
net-utils check-connection

# 发送GET请求
net-utils get https://api.github.com

# 扫描端口
net-utils scan-ports example.com 80,443,8080

主要功能

1. HTTP 请求工具

from net_utils_ky import HTTPClient

client = HTTPClient()

# GET请求
response = client.get("https://api.example.com/data")

# POST请求
data = {"name": "test", "value": 123}
response = client.post("https://api.example.com/submit", json=data)

# 带认证的请求
response = client.get("https://api.example.com/private",
                     auth=("username", "password"))

2. 网络连接检测

from net_utils_ky import NetworkChecker

checker = NetworkChecker()

# 检查基本网络连接
if checker.is_connected():
    print("网络连接正常")

# 检查特定网站连接
if checker.can_reach("https://www.google.com"):
    print("可以访问Google")

# 检查DNS解析
if checker.dns_works():
    print("DNS解析正常")

3. 端口扫描

from net_utils_ky import PortScanner

scanner = PortScanner()

# 扫描单个端口
if scanner.is_port_open("example.com", 80):
    print("端口80开放")

# 扫描端口范围
open_ports = scanner.scan_ports("example.com", range(80, 90))
print(f"开放的端口: {open_ports}")

4. 异步支持

import asyncio
from net_utils_ky import AsyncNetworkUtils

async def main():
    async_utils = AsyncNetworkUtils()

    # 异步HTTP请求
    response = await async_utils.get("https://api.example.com")
    print(f"异步响应: {response.status_code}")

    # 并发请求
    urls = ["https://api1.example.com", "https://api2.example.com"]
    responses = await async_utils.get_all(urls)

    for url, response in zip(urls, responses):
        print(f"{url}: {response.status_code}")

asyncio.run(main())

配置

代理设置

from net_utils_ky import NetworkUtils

# 设置HTTP代理
net_utils = NetworkUtils(proxy="http://proxy.example.com:8080")

# 设置SOCKS代理
net_utils = NetworkUtils(proxy="socks5://proxy.example.com:1080")

超时设置

from net_utils_ky import NetworkUtils

# 设置连接超时和读取超时
net_utils = NetworkUtils(timeout=(5, 30))  # (连接超时, 读取超时)

开发

安装开发依赖

pip install -e ".[dev]"

运行测试

pytest

代码格式化

black .

类型检查

mypy net_utils_ky

贡献

欢迎提交 Issue 和 Pull Request!

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开 Pull Request

许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。

更新日志

0.1.0 (2024-01-01)

  • 初始版本发布
  • 基本 HTTP 请求功能
  • 网络连接检测
  • 端口扫描功能
  • 异步支持

支持

如果您遇到问题或有建议,请:

  1. 查看 文档
  2. 搜索 现有 Issue
  3. 创建新的 Issue

致谢

感谢所有为这个项目做出贡献的开发者!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

net_utils_ky-0.3.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

net_utils_ky-0.3.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file net_utils_ky-0.3.0.tar.gz.

File metadata

  • Download URL: net_utils_ky-0.3.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for net_utils_ky-0.3.0.tar.gz
Algorithm Hash digest
SHA256 387d8324af8ac9b68a5100a73e0668f62f3c245f812c0a4cb255e9df5c8a0f9c
MD5 cb310277fe0f41b0466ad9005ab79aae
BLAKE2b-256 2778b5656cd4e2e4b1bb9b5fa8f60d477b55a932dc51d94aba4f49c240ccb9ae

See more details on using hashes here.

File details

Details for the file net_utils_ky-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: net_utils_ky-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for net_utils_ky-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 733981b3adcad88d6ccca05dfe7390bb9393726517031e24be3f5265cb9a9959
MD5 754d85b8eab7102e25f6dc467b920767
BLAKE2b-256 7ca1b5012ed0ed60716be6dbae97b30b23c09afc93520654cd68c00d96a77935

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page