port-test 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 linyuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: port_test
3
+ Version: 0.1.0
4
+ Summary: 测试port是否可用和随机一个port并测试。
5
+ Author: linyuan
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.6
8
+ Classifier: Programming Language :: Python :: 3.7
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Development Status :: 5 - Production/Stable
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: click>=8.0
24
+ Dynamic: license-file
25
+
26
+ # Port Test
27
+ **port test** 是一个轻便的port测试工具
28
+
29
+ **port test** It is a lightweight port testing tool.
30
+
31
+ ## 目录
32
+
33
+ - [安装](#安装)
34
+ - [用途](#用途)
35
+ - [命令行参数](#命令行参数)
36
+ - [许可证](#许可证)
37
+
38
+ ## Table of Contents
39
+
40
+ - [Installation](#installation)
41
+ - [Usage](#usage)
42
+ - [Command-line Arguments](#command-line-arguments)
43
+ - [License](#license)
44
+
45
+ ## 安装
46
+
47
+ 使用 `pip install port-test` 命令安装
48
+
49
+ ## Installation
50
+
51
+ Install with the command:
52
+ `pip install port-test`
53
+
54
+ ## 用途
55
+
56
+ **port_test**是一个轻便的port测试工具,你可以这样的示例进行测试127.0.0.1的5000端口是否可用
57
+ ```python
58
+ import port_test
59
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
60
+ ```
61
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
62
+ ```python
63
+ import port_test
64
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ **port_test** is a lightweight port testing tool.
70
+ Example: Check whether port 5000 on 127.0.0.1 is available.
71
+
72
+ ```python
73
+ import port_test
74
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
75
+ ```
76
+
77
+ Example: Get a random available port on 127.0.0.1
78
+
79
+ ```python
80
+ import port_test
81
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
82
+ ```
83
+
84
+ ## 命令行
85
+
86
+ 当然你也可以直接使用命令行,要用`test-port`,有这个参数`-tp`或`--TestPort_Or_RandomPortAndTest`这个要传入一个字符串
87
+
88
+ 你可以用这个示例测试127.0.0.1的5000端口是否可用
89
+
90
+ ```bash
91
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
92
+ ```
93
+
94
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
95
+
96
+ ```bash
97
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
98
+ ```
99
+
100
+ ## Command Line
101
+
102
+ You can also use it directly from the command line via `test-port`.
103
+ It provides the argument `-tp` or `--TestPort_Or_RandomPortAndTest`, which accepts a JSON string.
104
+
105
+ Example: Check if port 5000 on 127.0.0.1 is available
106
+
107
+ ```bash
108
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
109
+ ```
110
+
111
+ Example: Get a random available port on 127.0.0.1
112
+
113
+ ```bash
114
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
115
+ ```
116
+
117
+ ## 许可证
118
+
119
+ 本库使用 MIT 许可证,参见 LICENSE
120
+
121
+ ## License
122
+
123
+ This library is released under the MIT License. See LICENSE.
@@ -0,0 +1,98 @@
1
+ # Port Test
2
+ **port test** 是一个轻便的port测试工具
3
+
4
+ **port test** It is a lightweight port testing tool.
5
+
6
+ ## 目录
7
+
8
+ - [安装](#安装)
9
+ - [用途](#用途)
10
+ - [命令行参数](#命令行参数)
11
+ - [许可证](#许可证)
12
+
13
+ ## Table of Contents
14
+
15
+ - [Installation](#installation)
16
+ - [Usage](#usage)
17
+ - [Command-line Arguments](#command-line-arguments)
18
+ - [License](#license)
19
+
20
+ ## 安装
21
+
22
+ 使用 `pip install port-test` 命令安装
23
+
24
+ ## Installation
25
+
26
+ Install with the command:
27
+ `pip install port-test`
28
+
29
+ ## 用途
30
+
31
+ **port_test**是一个轻便的port测试工具,你可以这样的示例进行测试127.0.0.1的5000端口是否可用
32
+ ```python
33
+ import port_test
34
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
35
+ ```
36
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
37
+ ```python
38
+ import port_test
39
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ **port_test** is a lightweight port testing tool.
45
+ Example: Check whether port 5000 on 127.0.0.1 is available.
46
+
47
+ ```python
48
+ import port_test
49
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
50
+ ```
51
+
52
+ Example: Get a random available port on 127.0.0.1
53
+
54
+ ```python
55
+ import port_test
56
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
57
+ ```
58
+
59
+ ## 命令行
60
+
61
+ 当然你也可以直接使用命令行,要用`test-port`,有这个参数`-tp`或`--TestPort_Or_RandomPortAndTest`这个要传入一个字符串
62
+
63
+ 你可以用这个示例测试127.0.0.1的5000端口是否可用
64
+
65
+ ```bash
66
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
67
+ ```
68
+
69
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
70
+
71
+ ```bash
72
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
73
+ ```
74
+
75
+ ## Command Line
76
+
77
+ You can also use it directly from the command line via `test-port`.
78
+ It provides the argument `-tp` or `--TestPort_Or_RandomPortAndTest`, which accepts a JSON string.
79
+
80
+ Example: Check if port 5000 on 127.0.0.1 is available
81
+
82
+ ```bash
83
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
84
+ ```
85
+
86
+ Example: Get a random available port on 127.0.0.1
87
+
88
+ ```bash
89
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
90
+ ```
91
+
92
+ ## 许可证
93
+
94
+ 本库使用 MIT 许可证,参见 LICENSE
95
+
96
+ ## License
97
+
98
+ This library is released under the MIT License. See LICENSE.
@@ -0,0 +1,27 @@
1
+ import socket
2
+ import random
3
+
4
+ class Port:
5
+ def TestPort(self,port: int, host: str = "127.0.0.1",debug=False) -> bool:
6
+ if not (1 <= port <= 65535):
7
+ return False
8
+
9
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
10
+ try:
11
+ s.bind((host, port))
12
+ except OSError:
13
+ if debug:
14
+ return {"port":port,"host":host,"return":False}
15
+ else:
16
+ return False
17
+ if debug:
18
+ return {"port":port,"host":host,"return":True}
19
+ return True
20
+
21
+ def RandomPortAndTest(self,host="127.0.0.1",debug=False):
22
+ while True:
23
+ port=random.randint(1024,65535)
24
+ if self.TestPort(port=port,host=host,debug=False):
25
+ if debug:
26
+ return {"port":port,"host":host}
27
+ return port
@@ -0,0 +1,20 @@
1
+ from . import Port
2
+ import click
3
+ import json
4
+ @click.command(context_settings={"help_option_names": ["-h", "--help"]})
5
+ @click.option('-tp','--TestPort_Or_RandomPortAndTest',type=str,required=True)
6
+ def maim(TestPort_Or_RandomPortAndTest):
7
+ try:
8
+ data=json.loads(TestPort_Or_RandomPortAndTest)
9
+ except json.JSONDecodeError:
10
+ click.echo("!!!json.JSONDecodeError!!!", err=True)
11
+ return
12
+ if "random" not in data:click.echo('!!!json.KeyError,Missing parameter \"random?\"!!!', err=True);return
13
+ if not(data["random"]=="T" or data["random?"]=="F"):click.echo('!!!Value type error \"random?\"!!!', err=True);return
14
+ if "host" not in data:click.echo('!!!json.KeyError,Missing parameter \"host\"!!!', err=True);return
15
+ if "debug" not in data:click.echo('!!!json.KeyError,Missing parameter \"debug\"!!!', err=True);return
16
+ if data["random"] == "T":
17
+ print(Port.RandomPortAndTest(data["host"],bool(data["debug"])))
18
+ else:
19
+ if "port" not in data:click.echo('!!!json.KeyError,Missing parameter \"port\"!!!', err=True);return
20
+ print(Port.TestPort(data["port"],data["host"],bool(data["debug"])))
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: port_test
3
+ Version: 0.1.0
4
+ Summary: 测试port是否可用和随机一个port并测试。
5
+ Author: linyuan
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.6
8
+ Classifier: Programming Language :: Python :: 3.7
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Development Status :: 5 - Production/Stable
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: click>=8.0
24
+ Dynamic: license-file
25
+
26
+ # Port Test
27
+ **port test** 是一个轻便的port测试工具
28
+
29
+ **port test** It is a lightweight port testing tool.
30
+
31
+ ## 目录
32
+
33
+ - [安装](#安装)
34
+ - [用途](#用途)
35
+ - [命令行参数](#命令行参数)
36
+ - [许可证](#许可证)
37
+
38
+ ## Table of Contents
39
+
40
+ - [Installation](#installation)
41
+ - [Usage](#usage)
42
+ - [Command-line Arguments](#command-line-arguments)
43
+ - [License](#license)
44
+
45
+ ## 安装
46
+
47
+ 使用 `pip install port-test` 命令安装
48
+
49
+ ## Installation
50
+
51
+ Install with the command:
52
+ `pip install port-test`
53
+
54
+ ## 用途
55
+
56
+ **port_test**是一个轻便的port测试工具,你可以这样的示例进行测试127.0.0.1的5000端口是否可用
57
+ ```python
58
+ import port_test
59
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
60
+ ```
61
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
62
+ ```python
63
+ import port_test
64
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ **port_test** is a lightweight port testing tool.
70
+ Example: Check whether port 5000 on 127.0.0.1 is available.
71
+
72
+ ```python
73
+ import port_test
74
+ print(port_test.Port.TestPort(port=5000, host="127.0.0.1", debug=False))
75
+ ```
76
+
77
+ Example: Get a random available port on 127.0.0.1
78
+
79
+ ```python
80
+ import port_test
81
+ print(port_test.Port.RandomPortAndTest(host="127.0.0.1", debug=False))
82
+ ```
83
+
84
+ ## 命令行
85
+
86
+ 当然你也可以直接使用命令行,要用`test-port`,有这个参数`-tp`或`--TestPort_Or_RandomPortAndTest`这个要传入一个字符串
87
+
88
+ 你可以用这个示例测试127.0.0.1的5000端口是否可用
89
+
90
+ ```bash
91
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
92
+ ```
93
+
94
+ 你可以这样的示例进行随机一个127.0.0.1的可用端口
95
+
96
+ ```bash
97
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
98
+ ```
99
+
100
+ ## Command Line
101
+
102
+ You can also use it directly from the command line via `test-port`.
103
+ It provides the argument `-tp` or `--TestPort_Or_RandomPortAndTest`, which accepts a JSON string.
104
+
105
+ Example: Check if port 5000 on 127.0.0.1 is available
106
+
107
+ ```bash
108
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"F", "port":"5000", "host":"127.0.0.1", "debug":"False"}'
109
+ ```
110
+
111
+ Example: Get a random available port on 127.0.0.1
112
+
113
+ ```bash
114
+ test-port --TestPort_Or_RandomPortAndTest '{"random":"T", "host":"127.0.0.1", "debug":"False"}'
115
+ ```
116
+
117
+ ## 许可证
118
+
119
+ 本库使用 MIT 许可证,参见 LICENSE
120
+
121
+ ## License
122
+
123
+ This library is released under the MIT License. See LICENSE.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ port_test/__init__.py
5
+ port_test/cli.py
6
+ port_test.egg-info/PKG-INFO
7
+ port_test.egg-info/SOURCES.txt
8
+ port_test.egg-info/dependency_links.txt
9
+ port_test.egg-info/entry_points.txt
10
+ port_test.egg-info/requires.txt
11
+ port_test.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ test-port = port_test.cli:main
@@ -0,0 +1 @@
1
+ click>=8.0
@@ -0,0 +1 @@
1
+ port_test
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "port_test"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name = "linyuan" }
10
+ ]
11
+ description = """测试port是否可用和随机一个port并测试。
12
+ Test whether the port is available and randomly select a port for testing."""
13
+ readme = { file = "README.md", content-type = "text/markdown" }
14
+ requires-python = ">=3.7"
15
+ dependencies = ["click>=8.0"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.6",
19
+ "Programming Language :: Python :: 3.7",
20
+ "Programming Language :: Python :: 3.8",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ "License :: OSI Approved :: MIT License",
28
+ "Development Status :: 5 - Production/Stable",
29
+ "Intended Audience :: Developers",
30
+ "Topic :: Software Development :: Libraries :: Python Modules"
31
+ ]
32
+
33
+ [project.scripts]
34
+ test-port="port_test.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+