port-test 0.1.0__py3-none-any.whl
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.
- port_test/__init__.py +27 -0
- port_test/cli.py +20 -0
- port_test-0.1.0.dist-info/METADATA +123 -0
- port_test-0.1.0.dist-info/RECORD +8 -0
- port_test-0.1.0.dist-info/WHEEL +5 -0
- port_test-0.1.0.dist-info/entry_points.txt +2 -0
- port_test-0.1.0.dist-info/licenses/LICENSE +21 -0
- port_test-0.1.0.dist-info/top_level.txt +1 -0
port_test/__init__.py
ADDED
|
@@ -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
|
port_test/cli.py
ADDED
|
@@ -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,8 @@
|
|
|
1
|
+
port_test/__init__.py,sha256=XES6FA-4PfUgwDx2rIcMRqJWW7oq5bNryqLQadrFCcU,905
|
|
2
|
+
port_test/cli.py,sha256=JByoyVU6n2xPwA1RcZLSCrRb4G--ELyHanRSbgNqu_w,1144
|
|
3
|
+
port_test-0.1.0.dist-info/licenses/LICENSE,sha256=ajZuvJX_3YywSrqqopVGfQLyGc8eKU6D84C_TddevnE,1085
|
|
4
|
+
port_test-0.1.0.dist-info/METADATA,sha256=SGJi4X2hIXHWEv0XveaERlO0bZUursoy__YB89AK0Cs,3589
|
|
5
|
+
port_test-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
port_test-0.1.0.dist-info/entry_points.txt,sha256=XStVEs2c-AQxgAmQdt2_6d4x9AzQ0qjaqG8S3W7AQIE,49
|
|
7
|
+
port_test-0.1.0.dist-info/top_level.txt,sha256=xELiat21UmT0D6_V5zBOHyVshkE-0X9CpdImi7PZIwk,10
|
|
8
|
+
port_test-0.1.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
port_test
|