Skip to content

Commit

Permalink
v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehver committed Apr 7, 2024
1 parent 7f1833c commit b638b89
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
3 changes: 2 additions & 1 deletion #README/README-cn.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://github.com/Mehver/iController/raw/main/%23README/icon/256.png" width="20%"/>
<h1>iController <code>v0.4.1</code></h1>
<h1>iController <code>v0.4.2</code></h1>
<p><a href='https://github.com/Mehver/iController/blob/main/README.md'>English</a> | 简体中文</p>
</div>

Expand Down Expand Up @@ -112,6 +112,7 @@ source venv/bin/activate
- Pyperclip
- Pycaw (https://github.com/AndreMiras/pycaw)
- Comtypes
- Psutil (https://github.com/giampaolo/psutil)
- PyInstaller (https://www.pyinstaller.org/)
- (Dev) Auto-PY-To-EXE (https://github.com/brentvollebregt/auto-py-to-exe)

Expand Down
1 change: 0 additions & 1 deletion #README/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- ~~完善设置选项~~
- ~~侧边栏左右切换~~
- ~~灵敏度调整~~
- 关闭服务端按键

## v0.5.x

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://github.com/Mehver/iController/raw/main/%23README/icon/256.png" width="20%"/>
<h1>iController <code>v0.4.1</code></h1>
<h1>iController <code>v0.4.2</code></h1>
</tr>
<p>English | <a href='https://github.com/Mehver/iController/blob/main/%23README/README-cn.md'>简体中文</a></p>
</div>
Expand Down Expand Up @@ -120,6 +120,7 @@ mysterious errors. Only Python v3.10.10 is recommended.
- Pyperclip
- Pycaw (https://github.com/AndreMiras/pycaw)
- Comtypes
- Psutil (https://github.com/giampaolo/psutil)
- PyInstaller (https://www.pyinstaller.org/)
- (Dev) Auto-PY-To-EXE (https://github.com/brentvollebregt/auto-py-to-exe)

Expand Down
23 changes: 13 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from modules.server import server
from modules.portchecker import portchecker


print("""
_ ___ _ _ _
Expand All @@ -9,18 +10,20 @@
|_\____/\___/|_| |_|\__|_| \___/|_|_|\___|_|
https://github.com/Mehver/iController
v0.4.1
v0.4.2
""")

PORT = input("Give a port > ") # 获取用户输入的端口号
try:
PORT = int(PORT)
if PORT < 0 or PORT > 65535:
raise ValueError
except ValueError:
print("Invalid port number.")
sys.exit(1)
while True:
PORT = input("Give a port > ")
try:
PORT = int(PORT)
if not portchecker(PORT):
raise ValueError
except ValueError:
print("Invalid or unavailable port number. Please try again.")
else:
break

app = server() # 创建Flask应用实例

Expand Down
20 changes: 20 additions & 0 deletions modules/portchecker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import psutil


def portchecker(port):
"""
使用psutil检查端口是否可用
- 如果端口是一个数字且在合法范围内(1-65534)
- 并且没有被别的程序使用,则返回True
"""
# 确保端口号是整数且在合法范围内
if isinstance(port, int) and 0 < port < 65535:
# 获取当前所有的网络连接
connections = psutil.net_connections()
# 遍历所有连接,检查端口是否被占用
for conn in connections:
if conn.laddr.port == port:
return False # 端口已被占用
return True # 端口未被占用,可用
else:
return False # 端口号不合法
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pyautogui==0.9.54
pyinstaller==6.5.0
auto-py-to-exe==2.42.0
pycaw==20240210
comtypes==1.3.1
comtypes==1.3.1
psutil==5.9.8

0 comments on commit b638b89

Please sign in to comment.