kuro-net 1.0.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.
- kuro_net-1.0.0/LICENCE +21 -0
- kuro_net-1.0.0/PKG-INFO +82 -0
- kuro_net-1.0.0/README.md +70 -0
- kuro_net-1.0.0/kuro/__init__.py +6 -0
- kuro_net-1.0.0/kuro/client.py +36 -0
- kuro_net-1.0.0/kuro/command_parser.py +30 -0
- kuro_net-1.0.0/kuro/gui.py +144 -0
- kuro_net-1.0.0/kuro/protocol.py +18 -0
- kuro_net-1.0.0/kuro/scanner.py +29 -0
- kuro_net-1.0.0/kuro/server.py +98 -0
- kuro_net-1.0.0/kuro_net.egg-info/PKG-INFO +82 -0
- kuro_net-1.0.0/kuro_net.egg-info/SOURCES.txt +14 -0
- kuro_net-1.0.0/kuro_net.egg-info/dependency_links.txt +1 -0
- kuro_net-1.0.0/kuro_net.egg-info/top_level.txt +1 -0
- kuro_net-1.0.0/pyproject.toml +18 -0
- kuro_net-1.0.0/setup.cfg +4 -0
kuro_net-1.0.0/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alulattukasa26
|
|
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.
|
kuro_net-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kuro-net
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An asynchronous networking library for Python with a built-in GUI panel, command parser, and brute-force protection.
|
|
5
|
+
Author: alulattukasa26
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENCE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# kuro
|
|
14
|
+
|
|
15
|
+
An asynchronous networking library for Python with a built-in graphical control panel (`tkinter`), command parser, asynchronous port scanner, and brute-force protection.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
* **Asynchronous Core (`KuroServer`, `KuroClient`):** structured JSON packet exchange over TCP (`asyncio`) with `broadcast` support.
|
|
19
|
+
* **Routing Decorators:** convenient registration of message handlers (`@server.on_message`) and custom commands (`@server.command("...")`).
|
|
20
|
+
* **Security (`secrets` + anti-brute-force):** cryptographically secure `acc_token` generation, automatic IP banning upon exceeding the attempt limit (`max_attempts`), and manual ban management (`server.ban()`, `server.unban()`).
|
|
21
|
+
* **Built-in GUI (`GUIPanel`):** `tkinter`-based monitoring panel supporting dark, light, and custom themes, live client statistics, logs, and animations.
|
|
22
|
+
* **Additional Tools:** command lexer/parser (`CommandParser`) and an asynchronous port scanner with concurrency limits (`PortScanner`).
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install kuro-net
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Server with GUI Panel
|
|
33
|
+
```python
|
|
34
|
+
import asyncio
|
|
35
|
+
import threading
|
|
36
|
+
import kuro
|
|
37
|
+
|
|
38
|
+
server = kuro.KuroServer(host="0.0.0.0", port=5555, max_attempts=3)
|
|
39
|
+
panel = kuro.GUIPanel(server=server, theme="dark")
|
|
40
|
+
|
|
41
|
+
@server.on_message
|
|
42
|
+
async def handle_msg(writer, packet: kuro.Packet):
|
|
43
|
+
panel.log(f"[{packet.sender}]: {packet.data}")
|
|
44
|
+
await server.broadcast(packet, exclude_writer=writer)
|
|
45
|
+
|
|
46
|
+
def run_server():
|
|
47
|
+
asyncio.run(server.start())
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
threading.Thread(target=run_server, daemon=True).start()
|
|
51
|
+
panel.run()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Client with Command Parser
|
|
55
|
+
```python
|
|
56
|
+
import asyncio
|
|
57
|
+
import kuro
|
|
58
|
+
|
|
59
|
+
client = kuro.KuroClient(host="127.0.0.1", port=5555, name="User")
|
|
60
|
+
parser = kuro.CommandParser()
|
|
61
|
+
|
|
62
|
+
@client.on_message
|
|
63
|
+
async def on_msg(packet: kuro.Packet):
|
|
64
|
+
print(f"[{packet.sender}]: {packet.data}")
|
|
65
|
+
|
|
66
|
+
async def main():
|
|
67
|
+
await client.connect()
|
|
68
|
+
asyncio.create_task(client.listen())
|
|
69
|
+
parsed = parser.parse("msg Hello, kuro!")
|
|
70
|
+
if parsed:
|
|
71
|
+
await client.send(data=parsed.arg, command=parsed.cmd)
|
|
72
|
+
await asyncio.sleep(1)
|
|
73
|
+
await client.close()
|
|
74
|
+
|
|
75
|
+
asyncio.run(main())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Author
|
|
79
|
+
* GitHub: [alulattukasa26](https://github.com/alulattukasa26)
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
kuro_net-1.0.0/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# kuro
|
|
2
|
+
|
|
3
|
+
An asynchronous networking library for Python with a built-in graphical control panel (`tkinter`), command parser, asynchronous port scanner, and brute-force protection.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
* **Asynchronous Core (`KuroServer`, `KuroClient`):** structured JSON packet exchange over TCP (`asyncio`) with `broadcast` support.
|
|
7
|
+
* **Routing Decorators:** convenient registration of message handlers (`@server.on_message`) and custom commands (`@server.command("...")`).
|
|
8
|
+
* **Security (`secrets` + anti-brute-force):** cryptographically secure `acc_token` generation, automatic IP banning upon exceeding the attempt limit (`max_attempts`), and manual ban management (`server.ban()`, `server.unban()`).
|
|
9
|
+
* **Built-in GUI (`GUIPanel`):** `tkinter`-based monitoring panel supporting dark, light, and custom themes, live client statistics, logs, and animations.
|
|
10
|
+
* **Additional Tools:** command lexer/parser (`CommandParser`) and an asynchronous port scanner with concurrency limits (`PortScanner`).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install kuro-net
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### Server with GUI Panel
|
|
21
|
+
```python
|
|
22
|
+
import asyncio
|
|
23
|
+
import threading
|
|
24
|
+
import kuro
|
|
25
|
+
|
|
26
|
+
server = kuro.KuroServer(host="0.0.0.0", port=5555, max_attempts=3)
|
|
27
|
+
panel = kuro.GUIPanel(server=server, theme="dark")
|
|
28
|
+
|
|
29
|
+
@server.on_message
|
|
30
|
+
async def handle_msg(writer, packet: kuro.Packet):
|
|
31
|
+
panel.log(f"[{packet.sender}]: {packet.data}")
|
|
32
|
+
await server.broadcast(packet, exclude_writer=writer)
|
|
33
|
+
|
|
34
|
+
def run_server():
|
|
35
|
+
asyncio.run(server.start())
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
threading.Thread(target=run_server, daemon=True).start()
|
|
39
|
+
panel.run()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Client with Command Parser
|
|
43
|
+
```python
|
|
44
|
+
import asyncio
|
|
45
|
+
import kuro
|
|
46
|
+
|
|
47
|
+
client = kuro.KuroClient(host="127.0.0.1", port=5555, name="User")
|
|
48
|
+
parser = kuro.CommandParser()
|
|
49
|
+
|
|
50
|
+
@client.on_message
|
|
51
|
+
async def on_msg(packet: kuro.Packet):
|
|
52
|
+
print(f"[{packet.sender}]: {packet.data}")
|
|
53
|
+
|
|
54
|
+
async def main():
|
|
55
|
+
await client.connect()
|
|
56
|
+
asyncio.create_task(client.listen())
|
|
57
|
+
parsed = parser.parse("msg Hello, kuro!")
|
|
58
|
+
if parsed:
|
|
59
|
+
await client.send(data=parsed.arg, command=parsed.cmd)
|
|
60
|
+
await asyncio.sleep(1)
|
|
61
|
+
await client.close()
|
|
62
|
+
|
|
63
|
+
asyncio.run(main())
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Author
|
|
67
|
+
* GitHub: [alulattukasa26](https://github.com/alulattukasa26)
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from .protocol import Packet
|
|
3
|
+
|
|
4
|
+
class KuroClient:
|
|
5
|
+
def __init__(self, host: str = "127.0.0.1", port: int = 5555, name: str = "User"):
|
|
6
|
+
self.host = host
|
|
7
|
+
self.port = port
|
|
8
|
+
self.name = name
|
|
9
|
+
self.reader = None
|
|
10
|
+
self.writer = None
|
|
11
|
+
self._message_handler = None
|
|
12
|
+
|
|
13
|
+
def on_message(self, func):
|
|
14
|
+
self._message_handler = func
|
|
15
|
+
return func
|
|
16
|
+
|
|
17
|
+
async def connect(self):
|
|
18
|
+
self.reader, self.writer = await asyncio.open_connection(host=self.host, port=self.port)
|
|
19
|
+
|
|
20
|
+
async def send(self, data: str, command: str = "msg"):
|
|
21
|
+
packet = Packet(sender=self.name, command=command, data=data)
|
|
22
|
+
self.writer.write(packet.to_bytes())
|
|
23
|
+
await self.writer.drain()
|
|
24
|
+
|
|
25
|
+
async def listen(self):
|
|
26
|
+
while True:
|
|
27
|
+
raw = await self.reader.readline()
|
|
28
|
+
if not raw:
|
|
29
|
+
break
|
|
30
|
+
packet = Packet.from_bytes(raw)
|
|
31
|
+
if self._message_handler is not None:
|
|
32
|
+
await self._message_handler(packet)
|
|
33
|
+
|
|
34
|
+
async def close(self):
|
|
35
|
+
self.writer.close()
|
|
36
|
+
await self.writer.wait_closed()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
@dataclass
|
|
4
|
+
class ParsedCommand:
|
|
5
|
+
cmd: str
|
|
6
|
+
arg: str
|
|
7
|
+
|
|
8
|
+
class Lexer:
|
|
9
|
+
def tokenize(self, inp) -> list[str]:
|
|
10
|
+
inp = inp.strip()
|
|
11
|
+
if not inp:
|
|
12
|
+
return []
|
|
13
|
+
parts = inp.split(" ", 1)
|
|
14
|
+
return parts
|
|
15
|
+
|
|
16
|
+
class CommandParser:
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self.lexer = Lexer()
|
|
19
|
+
|
|
20
|
+
def parse(self, inp: str) -> ParsedCommand | None:
|
|
21
|
+
parts = self.lexer.tokenize(inp)
|
|
22
|
+
if not parts:
|
|
23
|
+
return None
|
|
24
|
+
cmd = parts[0].lower()
|
|
25
|
+
if len(parts) > 1:
|
|
26
|
+
arg = parts[1].strip()
|
|
27
|
+
else:
|
|
28
|
+
arg = ""
|
|
29
|
+
|
|
30
|
+
return ParsedCommand(cmd=cmd, arg=arg)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import tkinter as tk
|
|
2
|
+
import datetime
|
|
3
|
+
|
|
4
|
+
# vars init
|
|
5
|
+
THEMES = {
|
|
6
|
+
"dark": {
|
|
7
|
+
"bg": "#0d1117",
|
|
8
|
+
"panel": "#161b22",
|
|
9
|
+
"fg": "#e6edf3",
|
|
10
|
+
"accent": "#58a6ff",
|
|
11
|
+
},
|
|
12
|
+
"light": {
|
|
13
|
+
"bg": "#f3f4f6",
|
|
14
|
+
"panel": "#ffffff",
|
|
15
|
+
"fg": "#111827",
|
|
16
|
+
"accent": "#2563eb",
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class GUIPanel:
|
|
21
|
+
def __init__(self, server=None, size=(900, 600), pos=(100, 100), theme: str = "dark"):
|
|
22
|
+
self.server = server
|
|
23
|
+
self._token_visible = False
|
|
24
|
+
if isinstance(theme, dict):
|
|
25
|
+
self.colors = theme
|
|
26
|
+
else:
|
|
27
|
+
self.colors = THEMES.get(theme, THEMES["dark"])
|
|
28
|
+
self.root = tk.Tk()
|
|
29
|
+
self.root.title("^kuro^--GUIPanel")
|
|
30
|
+
self.root.geometry(f"{size[0]}x{size[1]}+{pos[0]}+{pos[1]}")
|
|
31
|
+
self.root.configure(bg=self.colors["bg"])
|
|
32
|
+
self._pulse_radius = 10
|
|
33
|
+
self._build_ui()
|
|
34
|
+
self._update_stats()
|
|
35
|
+
self._animate()
|
|
36
|
+
|
|
37
|
+
def _build_ui(self):
|
|
38
|
+
for i in range(0, 2):
|
|
39
|
+
self.root.grid_columnconfigure(i, weight=1)
|
|
40
|
+
self.root.grid_rowconfigure(i, weight=1)
|
|
41
|
+
|
|
42
|
+
# server information panel
|
|
43
|
+
server_frame = tk.Frame(self.root, bg=self.colors["panel"], padx=15, pady=15)
|
|
44
|
+
server_frame.grid(row=0, column=0, sticky="nsew", padx=8, pady=8)
|
|
45
|
+
|
|
46
|
+
# clients information panel
|
|
47
|
+
clients_frame = tk.Frame(self.root, bg=self.colors["panel"], padx=15, pady=15)
|
|
48
|
+
clients_frame.grid(row=1, column=0, sticky="nsew", padx=8, pady=8)
|
|
49
|
+
|
|
50
|
+
# Logs panel
|
|
51
|
+
logs_frame = tk.Frame(self.root, bg=self.colors["panel"], padx=15, pady=15)
|
|
52
|
+
logs_frame.grid(row=0, column=1, sticky="nsew", padx=8, pady=8)
|
|
53
|
+
|
|
54
|
+
# beautiful animation panel
|
|
55
|
+
animation_frame = tk.Frame(self.root, bg=self.colors["panel"], padx=15, pady=15)
|
|
56
|
+
animation_frame.grid(row=1, column=1, sticky="nsew", padx=8, pady=8)
|
|
57
|
+
|
|
58
|
+
host = self.server.host if self.server else "0.0.0.0"
|
|
59
|
+
port = self.server.port if self.server else 5555
|
|
60
|
+
tk.Label(server_frame, text=f"HOST:{host}", bg=self.colors["panel"], fg=self.colors["fg"]).pack(anchor="w")
|
|
61
|
+
tk.Label(server_frame, text=f"PORT:{port}", bg=self.colors["panel"], fg=self.colors["fg"]).pack(anchor="w")
|
|
62
|
+
|
|
63
|
+
self.token_label = tk.Label(server_frame, text="ACC_TOKEN: ***", bg=self.colors["panel"], fg=self.colors["fg"])
|
|
64
|
+
self.token_label.pack(anchor="w", pady=5)
|
|
65
|
+
|
|
66
|
+
self.token_btn = tk.Button(server_frame, text="Show", command=self._toggle_token)
|
|
67
|
+
self.token_btn.pack(anchor="w")
|
|
68
|
+
|
|
69
|
+
self.token_cp = tk.Button(server_frame, text="Copy", command=self._copy_token)
|
|
70
|
+
self.token_cp.pack(anchor="w")
|
|
71
|
+
|
|
72
|
+
self.clients_label = tk.Label(clients_frame, text="Clients count: 0", bg=self.colors["panel"], fg=self.colors["fg"])
|
|
73
|
+
self.clients_label.pack(anchor="w")
|
|
74
|
+
self.active_label = tk.Label(clients_frame, text="Most active: —", bg=self.colors["panel"], fg=self.colors["fg"])
|
|
75
|
+
self.active_label.pack(anchor="w")
|
|
76
|
+
self.hack_label = tk.Label(clients_frame, text="Hack attempts: 0", bg=self.colors["panel"], fg=self.colors["fg"])
|
|
77
|
+
self.hack_label.pack(anchor="w")
|
|
78
|
+
|
|
79
|
+
self.logs_box = tk.Text(logs_frame, bg=self.colors["bg"], fg=self.colors["fg"], state="disabled")
|
|
80
|
+
self.logs_box.pack(fill="both", expand=True)
|
|
81
|
+
|
|
82
|
+
self.canvas = tk.Canvas(animation_frame, bg=self.colors["bg"], highlightthickness=0)
|
|
83
|
+
self.canvas.pack(fill="both", expand=True)
|
|
84
|
+
|
|
85
|
+
def _toggle_token(self):
|
|
86
|
+
self._token_visible = not self._token_visible
|
|
87
|
+
if self._token_visible:
|
|
88
|
+
token = self.server.get_AccToken() if self.server else "root"
|
|
89
|
+
self.token_label.config(text=f"ACC_TOKEN:{token}")
|
|
90
|
+
self.token_btn.config(text="Hide")
|
|
91
|
+
else:
|
|
92
|
+
self.token_label.config(text="ACC_TOKEN: ***")
|
|
93
|
+
self.token_btn.config(text="Show")
|
|
94
|
+
|
|
95
|
+
def log(self, text: str):
|
|
96
|
+
time_str = datetime.datetime.now().strftime("%H:%M:%S")
|
|
97
|
+
line = f"[{time_str}] {text}\n"
|
|
98
|
+
def _insert():
|
|
99
|
+
self.logs_box.config(state="normal")
|
|
100
|
+
self.logs_box.insert("end", line)
|
|
101
|
+
self.logs_box.see("end")
|
|
102
|
+
self.logs_box.config(state="disabled")
|
|
103
|
+
self.root.after(0, _insert)
|
|
104
|
+
|
|
105
|
+
def _update_stats(self):
|
|
106
|
+
if self.server:
|
|
107
|
+
online = len(self.server.clients)
|
|
108
|
+
hacks = self.server.failed_tokens
|
|
109
|
+
if self.server.activity:
|
|
110
|
+
top_user = max(self.server.activity, key=self.server.activity.get)
|
|
111
|
+
top_str = f"{top_user} ({self.server.activity[top_user]})"
|
|
112
|
+
else:
|
|
113
|
+
top_str = "—"
|
|
114
|
+
self.clients_label.config(text=f"Clients count: {online}")
|
|
115
|
+
self.active_label.config(text=f"Most active: {top_str}")
|
|
116
|
+
self.hack_label.config(text=f"Hack attempts: {hacks}")
|
|
117
|
+
self.root.after(500, self._update_stats)
|
|
118
|
+
|
|
119
|
+
def _copy_token(self):
|
|
120
|
+
token = self.server.get_AccToken() if self.server else "root"
|
|
121
|
+
self.root.clipboard_clear()
|
|
122
|
+
self.root.clipboard_append(token)
|
|
123
|
+
|
|
124
|
+
def _animate(self):
|
|
125
|
+
self.canvas.delete("all")
|
|
126
|
+
w = self.canvas.winfo_width() or 300
|
|
127
|
+
h = self.canvas.winfo_height() or 200
|
|
128
|
+
cx, cy = w // 2, h // 2
|
|
129
|
+
|
|
130
|
+
for r in (40, 80):
|
|
131
|
+
self.canvas.create_oval(cx - r, cy - r, cx + r, cy + r, outline=self.colors["panel"], width=2)
|
|
132
|
+
|
|
133
|
+
r = self._pulse_radius
|
|
134
|
+
self.canvas.create_oval(cx - r, cy - r, cx + r, cy + r, outline=self.colors["accent"], width=2)
|
|
135
|
+
self.canvas.create_text(cx, cy, text="KURO ONLINE", fill=self.colors["fg"])
|
|
136
|
+
|
|
137
|
+
self._pulse_radius += 2
|
|
138
|
+
if self._pulse_radius > 95:
|
|
139
|
+
self._pulse_radius = 10
|
|
140
|
+
|
|
141
|
+
self.root.after(30, self._animate)
|
|
142
|
+
|
|
143
|
+
def run(self):
|
|
144
|
+
self.root.mainloop()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class Packet:
|
|
7
|
+
sender: str
|
|
8
|
+
command: str
|
|
9
|
+
data: str
|
|
10
|
+
|
|
11
|
+
def to_bytes(self) -> bytes:
|
|
12
|
+
json_str = json.dumps({"sender": self.sender, "command": self.command, "data": self.data}) + "\n"
|
|
13
|
+
return json_str.encode("utf-8")
|
|
14
|
+
@classmethod
|
|
15
|
+
def from_bytes(cls, raw_bytes: bytes) -> "Packet":
|
|
16
|
+
data = json.loads(raw_bytes.decode("utf-8").strip())
|
|
17
|
+
return cls(sender=data["sender"], command=data["command"], data=data["data"])
|
|
18
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class ScanResult:
|
|
6
|
+
port: int
|
|
7
|
+
is_open: bool
|
|
8
|
+
|
|
9
|
+
class PortScanner:
|
|
10
|
+
def __init__(self, host: str = "127.0.0.1", timeout: float = 0.5, limit: int = 200):
|
|
11
|
+
self.host = host
|
|
12
|
+
self.timeout = timeout
|
|
13
|
+
self.sem = asyncio.Semaphore(limit)
|
|
14
|
+
|
|
15
|
+
async def _check_port(self, port: int):
|
|
16
|
+
async with self.sem:
|
|
17
|
+
try:
|
|
18
|
+
reader, writer = await asyncio.wait_for(asyncio.open_connection(host=self.host, port=port), timeout=self.timeout)
|
|
19
|
+
writer.close()
|
|
20
|
+
await writer.wait_closed()
|
|
21
|
+
return ScanResult(port, True)
|
|
22
|
+
except:
|
|
23
|
+
return ScanResult(port, False)
|
|
24
|
+
|
|
25
|
+
async def scan(self, start_port: int, end_port: int) -> list[ScanResult]:
|
|
26
|
+
tasks = [self._check_port(port) for port in range(start_port, end_port + 1)]
|
|
27
|
+
results = await asyncio.gather(*tasks)
|
|
28
|
+
return [res for res in results if res.is_open]
|
|
29
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from .protocol import Packet
|
|
3
|
+
import secrets
|
|
4
|
+
|
|
5
|
+
class KuroServer:
|
|
6
|
+
def __init__(self, host: str = "0.0.0.0", port: int = 5555, acc_token: str | None = None, max_attempts: int = 3):
|
|
7
|
+
self.host = host
|
|
8
|
+
self.port = port
|
|
9
|
+
self.clients = []
|
|
10
|
+
self._message_handler = None
|
|
11
|
+
self._commands = {}
|
|
12
|
+
self._max_attempts = max_attempts
|
|
13
|
+
if acc_token is None:
|
|
14
|
+
self._acc_token = secrets.token_urlsafe(24)
|
|
15
|
+
else:
|
|
16
|
+
self._acc_token = acc_token
|
|
17
|
+
self._failed_attempts = {}
|
|
18
|
+
self._banned_ips = set()
|
|
19
|
+
self.failed_tokens = 0
|
|
20
|
+
self.activity = {}
|
|
21
|
+
|
|
22
|
+
def on_message(self, func):
|
|
23
|
+
self._message_handler = func
|
|
24
|
+
return func
|
|
25
|
+
|
|
26
|
+
async def broadcast(self, packet: Packet, exclude_writer = None):
|
|
27
|
+
raw_bytes = packet.to_bytes()
|
|
28
|
+
for client in self.clients:
|
|
29
|
+
if client != exclude_writer:
|
|
30
|
+
client.write(raw_bytes)
|
|
31
|
+
await client.drain()
|
|
32
|
+
|
|
33
|
+
async def _handle_client(self, reader, writer):
|
|
34
|
+
peer = writer.get_extra_info("peername")
|
|
35
|
+
ip = peer[0] if peer else "unknown"
|
|
36
|
+
if ip in self._banned_ips:
|
|
37
|
+
writer.close()
|
|
38
|
+
await writer.wait_closed()
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
self.clients.append(writer)
|
|
42
|
+
try:
|
|
43
|
+
while True:
|
|
44
|
+
raw = await reader.readline()
|
|
45
|
+
if not raw:
|
|
46
|
+
break
|
|
47
|
+
packet = Packet.from_bytes(raw)
|
|
48
|
+
self.activity[packet.sender] = self.activity.get(packet.sender, 0) + 1
|
|
49
|
+
|
|
50
|
+
cmd_name = packet.command.lower()
|
|
51
|
+
if cmd_name in self._commands:
|
|
52
|
+
await self._commands[cmd_name](writer, packet)
|
|
53
|
+
elif self._message_handler is not None:
|
|
54
|
+
await self._message_handler(writer, packet)
|
|
55
|
+
|
|
56
|
+
finally:
|
|
57
|
+
if writer in self.clients: self.clients.remove(writer)
|
|
58
|
+
writer.close()
|
|
59
|
+
await writer.wait_closed()
|
|
60
|
+
|
|
61
|
+
def get_AccToken(self):
|
|
62
|
+
return self._acc_token
|
|
63
|
+
|
|
64
|
+
def check_AccToken(self, token: str, writer=None) -> bool:
|
|
65
|
+
if token == self._acc_token:
|
|
66
|
+
return True
|
|
67
|
+
|
|
68
|
+
self.failed_tokens += 1
|
|
69
|
+
if writer is not None:
|
|
70
|
+
peer = writer.get_extra_info("peername")
|
|
71
|
+
ip = peer[0] if peer else "unknown"
|
|
72
|
+
self._failed_attempts[ip] = self._failed_attempts.get(ip, 0) + 1
|
|
73
|
+
if self._failed_attempts[ip] >= self._max_attempts:
|
|
74
|
+
self.ban(ip)
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def ban(self, target):
|
|
78
|
+
if isinstance(target, str):
|
|
79
|
+
ip = target
|
|
80
|
+
else:
|
|
81
|
+
peer = target.get_extra_info("peername")
|
|
82
|
+
ip = peer[0] if peer else "unknown"
|
|
83
|
+
target.close()
|
|
84
|
+
self._banned_ips.add(ip)
|
|
85
|
+
|
|
86
|
+
def is_banned(self, ip: str):
|
|
87
|
+
self._banned_ips.discard(ip)
|
|
88
|
+
self._failed_attempts.pop(ip, None)
|
|
89
|
+
|
|
90
|
+
def command(self, cmd: str):
|
|
91
|
+
def dec(func):
|
|
92
|
+
self._commands[cmd.lower()] = func
|
|
93
|
+
return func
|
|
94
|
+
return dec
|
|
95
|
+
|
|
96
|
+
async def start(self):
|
|
97
|
+
server = await asyncio.start_server(self._handle_client, host=self.host, port=self.port)
|
|
98
|
+
async with server: await server.serve_forever()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kuro-net
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An asynchronous networking library for Python with a built-in GUI panel, command parser, and brute-force protection.
|
|
5
|
+
Author: alulattukasa26
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENCE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# kuro
|
|
14
|
+
|
|
15
|
+
An asynchronous networking library for Python with a built-in graphical control panel (`tkinter`), command parser, asynchronous port scanner, and brute-force protection.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
* **Asynchronous Core (`KuroServer`, `KuroClient`):** structured JSON packet exchange over TCP (`asyncio`) with `broadcast` support.
|
|
19
|
+
* **Routing Decorators:** convenient registration of message handlers (`@server.on_message`) and custom commands (`@server.command("...")`).
|
|
20
|
+
* **Security (`secrets` + anti-brute-force):** cryptographically secure `acc_token` generation, automatic IP banning upon exceeding the attempt limit (`max_attempts`), and manual ban management (`server.ban()`, `server.unban()`).
|
|
21
|
+
* **Built-in GUI (`GUIPanel`):** `tkinter`-based monitoring panel supporting dark, light, and custom themes, live client statistics, logs, and animations.
|
|
22
|
+
* **Additional Tools:** command lexer/parser (`CommandParser`) and an asynchronous port scanner with concurrency limits (`PortScanner`).
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install kuro-net
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Server with GUI Panel
|
|
33
|
+
```python
|
|
34
|
+
import asyncio
|
|
35
|
+
import threading
|
|
36
|
+
import kuro
|
|
37
|
+
|
|
38
|
+
server = kuro.KuroServer(host="0.0.0.0", port=5555, max_attempts=3)
|
|
39
|
+
panel = kuro.GUIPanel(server=server, theme="dark")
|
|
40
|
+
|
|
41
|
+
@server.on_message
|
|
42
|
+
async def handle_msg(writer, packet: kuro.Packet):
|
|
43
|
+
panel.log(f"[{packet.sender}]: {packet.data}")
|
|
44
|
+
await server.broadcast(packet, exclude_writer=writer)
|
|
45
|
+
|
|
46
|
+
def run_server():
|
|
47
|
+
asyncio.run(server.start())
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
threading.Thread(target=run_server, daemon=True).start()
|
|
51
|
+
panel.run()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Client with Command Parser
|
|
55
|
+
```python
|
|
56
|
+
import asyncio
|
|
57
|
+
import kuro
|
|
58
|
+
|
|
59
|
+
client = kuro.KuroClient(host="127.0.0.1", port=5555, name="User")
|
|
60
|
+
parser = kuro.CommandParser()
|
|
61
|
+
|
|
62
|
+
@client.on_message
|
|
63
|
+
async def on_msg(packet: kuro.Packet):
|
|
64
|
+
print(f"[{packet.sender}]: {packet.data}")
|
|
65
|
+
|
|
66
|
+
async def main():
|
|
67
|
+
await client.connect()
|
|
68
|
+
asyncio.create_task(client.listen())
|
|
69
|
+
parsed = parser.parse("msg Hello, kuro!")
|
|
70
|
+
if parsed:
|
|
71
|
+
await client.send(data=parsed.arg, command=parsed.cmd)
|
|
72
|
+
await asyncio.sleep(1)
|
|
73
|
+
await client.close()
|
|
74
|
+
|
|
75
|
+
asyncio.run(main())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Author
|
|
79
|
+
* GitHub: [alulattukasa26](https://github.com/alulattukasa26)
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENCE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
kuro/__init__.py
|
|
5
|
+
kuro/client.py
|
|
6
|
+
kuro/command_parser.py
|
|
7
|
+
kuro/gui.py
|
|
8
|
+
kuro/protocol.py
|
|
9
|
+
kuro/scanner.py
|
|
10
|
+
kuro/server.py
|
|
11
|
+
kuro_net.egg-info/PKG-INFO
|
|
12
|
+
kuro_net.egg-info/SOURCES.txt
|
|
13
|
+
kuro_net.egg-info/dependency_links.txt
|
|
14
|
+
kuro_net.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kuro
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kuro-net"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "An asynchronous networking library for Python with a built-in GUI panel, command parser, and brute-force protection."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "alulattukasa26"}
|
|
14
|
+
]
|
|
15
|
+
dependencies = []
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com"
|
kuro_net-1.0.0/setup.cfg
ADDED