shareit 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.
- shareit-0.1.0/LICENSE +21 -0
- shareit-0.1.0/PKG-INFO +14 -0
- shareit-0.1.0/pyproject.toml +19 -0
- shareit-0.1.0/shareit/__init__.py +0 -0
- shareit-0.1.0/shareit/cli.py +121 -0
shareit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fahad Ahammed
|
|
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.
|
shareit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: shareit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple file sharing CLI tool.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Fahad Ahammed
|
|
7
|
+
Requires-Python: >=3.11,<4.0
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Requires-Dist: psutil (==7.0.0)
|
|
14
|
+
Requires-Dist: rich (==14.0.0)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "shareit"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A simple file sharing CLI tool."
|
|
5
|
+
authors = ["Fahad Ahammed"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = ">=3.11,<4.0"
|
|
10
|
+
psutil = "7.0.0"
|
|
11
|
+
rich = "14.0.0"
|
|
12
|
+
|
|
13
|
+
[tool.poetry.scripts]
|
|
14
|
+
shareit = "shareit.cli:main"
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["poetry-core>=1.0.0"]
|
|
18
|
+
build-backend = "poetry.core.masonry.api"
|
|
19
|
+
|
|
File without changes
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import psutil
|
|
3
|
+
import ipaddress
|
|
4
|
+
import os
|
|
5
|
+
from rich import print as rprint
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
from rich.prompt import Prompt
|
|
9
|
+
|
|
10
|
+
import http.server as http_server
|
|
11
|
+
import socketserver
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def is_valid_ip(ip):
|
|
15
|
+
try:
|
|
16
|
+
ipaddress.ip_address(ip)
|
|
17
|
+
return True
|
|
18
|
+
except ValueError:
|
|
19
|
+
return False
|
|
20
|
+
|
|
21
|
+
def get_all_ip_addresses():
|
|
22
|
+
"""Return a dict of interface: [ip addresses] using psutil for cross-platform support."""
|
|
23
|
+
ip_dict = {}
|
|
24
|
+
for iface, addrs in psutil.net_if_addrs().items():
|
|
25
|
+
for addr in addrs:
|
|
26
|
+
if addr.family == 2: # AF_INET
|
|
27
|
+
ip_dict.setdefault(iface, []).append(addr.address)
|
|
28
|
+
return ip_dict
|
|
29
|
+
|
|
30
|
+
def file_share(directory, host="0.0.0.0", port=18338):
|
|
31
|
+
"""Function to share files over the network."""
|
|
32
|
+
# This function will implement the file sharing logic.
|
|
33
|
+
# For now, it just prints the parameters.
|
|
34
|
+
rprint(Panel.fit(f"[bold green]Sharing directory:[/] [yellow]{directory}[/] on [cyan]{host}:{port}[/]", title="[bold blue]shareit File Server"))
|
|
35
|
+
if not os.path.isdir(directory):
|
|
36
|
+
rprint(f"[bold red]Error:[/] The directory [yellow]{directory}[/] does not exist or is not a directory.")
|
|
37
|
+
return
|
|
38
|
+
rprint(f"[bold green]Directory [yellow]{directory}[/] is valid. Ready to share files.[/]")
|
|
39
|
+
|
|
40
|
+
os.chdir(directory) # Change to the directory to share
|
|
41
|
+
handler = http_server.SimpleHTTPRequestHandler
|
|
42
|
+
with socketserver.TCPServer((host, port), handler) as httpd:
|
|
43
|
+
rprint(Panel.fit("[bold green]File sharing service started successfully![/]", title="[bold blue]Server Status"))
|
|
44
|
+
if host == "0.0.0.0":
|
|
45
|
+
rprint("[bold yellow]Files are available on the following IP addresses:[/]")
|
|
46
|
+
table = Table(title="Access URLs", show_header=True, header_style="bold magenta")
|
|
47
|
+
table.add_column("Interface", style="dim")
|
|
48
|
+
table.add_column("IP Address")
|
|
49
|
+
table.add_column("URL")
|
|
50
|
+
for iface, ips in get_all_ip_addresses().items():
|
|
51
|
+
for ip in ips:
|
|
52
|
+
if ip != "0.0.0.0":
|
|
53
|
+
url = f"http://{ip}:{port}"
|
|
54
|
+
table.add_row(iface, ip, url)
|
|
55
|
+
rprint(table)
|
|
56
|
+
else:
|
|
57
|
+
url = f"http://{host}:{port}"
|
|
58
|
+
rprint(f"[bold green]Serving HTTP on [yellow]{host}:{port}[/] ([cyan]{url}[/])")
|
|
59
|
+
rprint(f"[bold blue]Access your files at [underline]{url}[/]")
|
|
60
|
+
try:
|
|
61
|
+
httpd.serve_forever()
|
|
62
|
+
except KeyboardInterrupt:
|
|
63
|
+
rprint("\n[bold red]Server stopped by user.[/]")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main():
|
|
67
|
+
parser = argparse.ArgumentParser(description="Share files over the network.")
|
|
68
|
+
parser.add_argument('--dir', type=str, default='.', help='Directory to share (default: current directory)')
|
|
69
|
+
parser.add_argument('--host', type=str, default='0.0.0.0', help='Host to bind (default: 0.0.0.0)')
|
|
70
|
+
parser.add_argument('--port', type=int, default=18338, help='Port to bind (default: 18338)')
|
|
71
|
+
args = parser.parse_args()
|
|
72
|
+
rprint("[bold white]Welcome to shareit CLI File Sharing Tool[/]")
|
|
73
|
+
rprint("[bold white]───────────────────────────────────────────")
|
|
74
|
+
ip_addresses = ["0.0.0.0"]
|
|
75
|
+
|
|
76
|
+
the_host = args.host
|
|
77
|
+
if not is_valid_ip(args.host):
|
|
78
|
+
rprint(f"[bold white]Provided host {args.host} is not a valid IP address. Using default host: 0.0.0.0")
|
|
79
|
+
the_host = "0.0.0.0"
|
|
80
|
+
|
|
81
|
+
for iface, ips in get_all_ip_addresses().items():
|
|
82
|
+
for ip in ips:
|
|
83
|
+
ip_addresses.append(ip)
|
|
84
|
+
ip_addresses.remove("127.0.0.1") # Exclude loopback address
|
|
85
|
+
if the_host not in ip_addresses:
|
|
86
|
+
rprint("[bold white]Provided host is not a valid local IP address. Select appropriate host from the following:")
|
|
87
|
+
|
|
88
|
+
table = Table(title="Available IP Addresses", show_header=True, header_style="bold magenta")
|
|
89
|
+
table.add_column("Index", style="dim")
|
|
90
|
+
table.add_column("IP Address")
|
|
91
|
+
for idx, ip in enumerate(ip_addresses):
|
|
92
|
+
table.add_row(str(idx), ip)
|
|
93
|
+
rprint(table)
|
|
94
|
+
|
|
95
|
+
ip_choice = Prompt.ask("[bold green]Enter the index of the IP address you want to use[/]")
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
ip_choice = int(ip_choice)
|
|
99
|
+
if 0 <= ip_choice < len(ip_addresses):
|
|
100
|
+
the_host = ip_addresses[ip_choice]
|
|
101
|
+
else:
|
|
102
|
+
rprint("[bold white]Invalid index. Using default host.")
|
|
103
|
+
except ValueError:
|
|
104
|
+
rprint("[bold orange]Invalid input. Using default host.")
|
|
105
|
+
rprint(f"Using host: {the_host}")
|
|
106
|
+
rprint(f"Using host: {the_host}")
|
|
107
|
+
try:
|
|
108
|
+
file_share(args.dir, the_host, args.port)
|
|
109
|
+
except Exception as e:
|
|
110
|
+
rprint(f"[bold red]Error:[/] {e}")
|
|
111
|
+
rprint("[bold red]Failed to start file sharing service.[/]")
|
|
112
|
+
rprint("[bold yellow]Make sure the directory exists and you have permission to access it.[/]")
|
|
113
|
+
rprint("[bold yellow]You can also try running the script with elevated privileges if necessary.[/]")
|
|
114
|
+
rprint("[bold red]Exiting...[/]")
|
|
115
|
+
exit(1)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__":
|
|
121
|
+
main()
|