-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
54 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
- 黑名单模式 | ||
- 控制权释放机制 | ||
- 提供HTTPS | ||
- 自扫描可用端口,检验可用性 | ||
- ~~自扫描可用端口,检验可用性~~ | ||
|
||
## v0.6.x | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
import psutil | ||
|
||
import socket | ||
import platform | ||
|
||
def portchecker(port): | ||
""" | ||
使用psutil检查端口是否可用 | ||
检查端口是否可用。 | ||
- 如果端口是一个数字且在合法范围内(1-65534) | ||
- 并且没有被别的程序使用,则返回True | ||
- 并且没有被别的程序使用,则返回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 # 端口未被占用,可用 | ||
os_name = platform.system() | ||
if os_name == 'Windows': | ||
# Windows下使用psutil检查 | ||
import psutil | ||
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 # 端口号不合法 | ||
elif os_name == 'Darwin': | ||
# MacOS下使用socket尝试绑定端口检查 | ||
if isinstance(port, int) and 0 < port < 65535: | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
try: | ||
s.bind(('localhost', port)) | ||
return True # 端口未被占用,可用 | ||
except socket.error: | ||
return False # 端口已被占用 | ||
else: | ||
return False # 端口号不合法 | ||
else: | ||
return False # 端口号不合法 | ||
raise NotImplementedError("This OS is not supported for port checking") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from modules.volume.base import BaseVolumeController | ||
from modules.volume.windows import WindowsVolumeController | ||
from modules.volume.mac import MacVolumeController | ||
import platform | ||
|
||
|
||
def get_volume_controller() -> BaseVolumeController: | ||
os_name = platform.system() | ||
if os_name == 'Windows': | ||
from modules.volume.windows import WindowsVolumeController | ||
return WindowsVolumeController() | ||
elif os_name == 'Darwin': # macOS的官方名称是Darwin | ||
elif os_name == 'Darwin': | ||
from modules.volume.mac import MacVolumeController | ||
return MacVolumeController() | ||
else: | ||
raise NotImplementedError("This OS is not supported for volume control.") | ||
raise NotImplementedError("This OS is not supported for volume control") | ||
|