helper-cli 0.1.1__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.
helper/main.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import platform
|
|
3
|
+
import subprocess
|
|
4
|
+
import socket
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
def run_cmd(cmd):
|
|
8
|
+
print(f"$ {cmd}")
|
|
9
|
+
try:
|
|
10
|
+
result = subprocess.check_output(cmd, shell=True, text=True).strip()
|
|
11
|
+
print(result)
|
|
12
|
+
except subprocess.CalledProcessError as e:
|
|
13
|
+
print(f"Error: {e}")
|
|
14
|
+
|
|
15
|
+
@click.group()
|
|
16
|
+
def cli():
|
|
17
|
+
"""Helper CLI - quick system info"""
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
@cli.command()
|
|
21
|
+
def internal_ip():
|
|
22
|
+
"""Show local/internal IP"""
|
|
23
|
+
system = platform.system()
|
|
24
|
+
if system == "Darwin":
|
|
25
|
+
cmd = "ipconfig getifaddr en0"
|
|
26
|
+
elif system == "Linux":
|
|
27
|
+
# Prefer ifconfig if available, else hostname -I
|
|
28
|
+
if shutil.which("ifconfig"):
|
|
29
|
+
cmd = "ifconfig | grep 'inet ' | grep -v 192.168.1.1 | awk '{print $2}' | head -n1"
|
|
30
|
+
else:
|
|
31
|
+
cmd = "hostname -I | awk '{print $1}'"
|
|
32
|
+
else:
|
|
33
|
+
ip = socket.gethostbyname(socket.gethostname())
|
|
34
|
+
print(f"$ python socket.gethostbyname(socket.gethostname())")
|
|
35
|
+
print(ip)
|
|
36
|
+
return
|
|
37
|
+
run_cmd(cmd)
|
|
38
|
+
|
|
39
|
+
@cli.command()
|
|
40
|
+
def public_ip():
|
|
41
|
+
"""Show public IP"""
|
|
42
|
+
cmd = "curl -s ifconfig.me"
|
|
43
|
+
run_cmd(cmd)
|
|
44
|
+
|
|
45
|
+
@cli.command()
|
|
46
|
+
def arch():
|
|
47
|
+
"""Show CPU architecture"""
|
|
48
|
+
cmd = "uname -m"
|
|
49
|
+
run_cmd(cmd)
|
|
50
|
+
|
|
51
|
+
@cli.command()
|
|
52
|
+
@click.pass_context
|
|
53
|
+
def all(ctx):
|
|
54
|
+
"""Show all info"""
|
|
55
|
+
click.echo("=== Internal IP ===")
|
|
56
|
+
ctx.invoke(internal_ip)
|
|
57
|
+
click.echo("\n=== Public IP ===")
|
|
58
|
+
ctx.invoke(public_ip)
|
|
59
|
+
click.echo("\n=== Architecture ===")
|
|
60
|
+
ctx.invoke(arch)
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
cli()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
helper/main.py,sha256=TTB6NuLydg2EcMlV2NxyYwKLag6tGuQhxbwNBBiOanU,1520
|
|
2
|
+
helper_cli-0.1.1.dist-info/METADATA,sha256=PBrA7-WIggiEiRpXGrCJNbCCXsKkWKQAyzoJlt1lxBw,75
|
|
3
|
+
helper_cli-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
helper_cli-0.1.1.dist-info/entry_points.txt,sha256=4EoFQ0yRogLTvStcbjlpkTqayWmiRqbMwkcDBcgQbK8,43
|
|
5
|
+
helper_cli-0.1.1.dist-info/top_level.txt,sha256=VM8lkErPJijbKhnfEGA_hE_YDXde4iizgqWKloZIxW8,7
|
|
6
|
+
helper_cli-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
helper
|