dargslan-lsof-audit 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.
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-lsof-audit
3
+ Version: 1.0.0
4
+ Summary: Open files and ports auditor
5
+ Author-email: Dargslan <info@dargslan.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://dargslan.com
8
+ Project-URL: Documentation, https://dargslan.com/cheat-sheets
9
+ Project-URL: Repository, https://dargslan.com/blog
10
+ Project-URL: eBook Store, https://dargslan.com/books
11
+ Keywords: linux,sysadmin,security,devops,cli,server
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: System :: Systems Administration
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+
21
+ # dargslan-lsof-audit
22
+
23
+ Audits open files, network connections, and listening ports via lsof
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install dargslan-lsof-audit
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ lsof-audit
35
+ lsof-audit --help
36
+ lsof-audit --json
37
+ ```
38
+
39
+ ## Part of Dargslan Toolkit
40
+
41
+ Install all 100+ Linux sysadmin tools:
42
+
43
+ ```bash
44
+ pip install dargslan-toolkit
45
+ ```
46
+
47
+ ## Resources
48
+
49
+ - [Dargslan eBook Store](https://dargslan.com/books) — 210+ Linux & cybersecurity eBooks
50
+ - [Linux Cheat Sheets](https://dargslan.com/cheat-sheets) — 370+ downloadable PDFs
51
+ - [Blog & Tutorials](https://dargslan.com/blog) — SEO guides and tutorials
52
+
53
+ ## License
54
+
55
+ MIT — [dargslan.com](https://dargslan.com)
@@ -0,0 +1,35 @@
1
+ # dargslan-lsof-audit
2
+
3
+ Audits open files, network connections, and listening ports via lsof
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install dargslan-lsof-audit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ lsof-audit
15
+ lsof-audit --help
16
+ lsof-audit --json
17
+ ```
18
+
19
+ ## Part of Dargslan Toolkit
20
+
21
+ Install all 100+ Linux sysadmin tools:
22
+
23
+ ```bash
24
+ pip install dargslan-toolkit
25
+ ```
26
+
27
+ ## Resources
28
+
29
+ - [Dargslan eBook Store](https://dargslan.com/books) — 210+ Linux & cybersecurity eBooks
30
+ - [Linux Cheat Sheets](https://dargslan.com/cheat-sheets) — 370+ downloadable PDFs
31
+ - [Blog & Tutorials](https://dargslan.com/blog) — SEO guides and tutorials
32
+
33
+ ## License
34
+
35
+ MIT — [dargslan.com](https://dargslan.com)
@@ -0,0 +1,3 @@
1
+ """dargslan-lsof-audit — Open files and ports auditor"""
2
+ __version__ = "1.0.0"
3
+ __author__ = "Dargslan"
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env python3
2
+ """dargslan-lsof-audit — Open files and ports auditor CLI"""
3
+
4
+ import subprocess
5
+ import json
6
+ import argparse
7
+ import sys
8
+
9
+
10
+ def run_cmd(cmd):
11
+ try:
12
+ r = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=30)
13
+ return r.stdout.strip()
14
+ except Exception:
15
+ return ""
16
+
17
+
18
+ def get_listening_ports():
19
+ output = run_cmd("lsof -i -P -n 2>/dev/null | grep LISTEN | head -20")
20
+ if not output:
21
+ output = run_cmd("ss -tlnp 2>/dev/null | head -20")
22
+ results = []
23
+ if output:
24
+ for line in output.strip().split("\n"):
25
+ if line.strip():
26
+ results.append(line.strip())
27
+ return results
28
+
29
+
30
+ def get_open_file_count():
31
+ output = run_cmd("lsof 2>/dev/null | wc -l")
32
+ try:
33
+ return int(output)
34
+ except (ValueError, TypeError):
35
+ return 0
36
+
37
+
38
+ def get_deleted_files():
39
+ output = run_cmd("lsof 2>/dev/null | grep '(deleted)' | head -10")
40
+ results = []
41
+ if output:
42
+ for line in output.strip().split("\n"):
43
+ if line.strip():
44
+ results.append(line.strip()[:100])
45
+ return results
46
+
47
+
48
+ def get_top_processes():
49
+ output = run_cmd("lsof 2>/dev/null | awk '{print $1}' | sort | uniq -c | sort -rn | head -10")
50
+ results = []
51
+ if output:
52
+ for line in output.strip().split("\n"):
53
+ if line.strip():
54
+ parts = line.strip().split()
55
+ if len(parts) >= 2:
56
+ results.append({"count": parts[0], "process": parts[1]})
57
+ return results
58
+
59
+
60
+ def get_network_connections():
61
+ output = run_cmd("lsof -i -P -n 2>/dev/null | grep -E 'ESTABLISHED|SYN' | head -10")
62
+ if not output:
63
+ output = run_cmd("ss -tnp 2>/dev/null | grep ESTAB | head -10")
64
+ results = []
65
+ if output:
66
+ for line in output.strip().split("\n"):
67
+ if line.strip():
68
+ results.append(line.strip()[:120])
69
+ return results
70
+
71
+
72
+ def main():
73
+ parser = argparse.ArgumentParser(
74
+ description="Open files and ports auditor — dargslan.com",
75
+ epilog="More tools: pip install dargslan-toolkit | https://dargslan.com"
76
+ )
77
+ parser.add_argument("--json", action="store_true", help="JSON output")
78
+ parser.add_argument("--ports", action="store_true", help="Show listening ports only")
79
+ args = parser.parse_args()
80
+
81
+ results = {
82
+ "tool": "dargslan-lsof-audit",
83
+ "version": "1.0.0",
84
+ "open_file_count": get_open_file_count(),
85
+ "listening_ports": get_listening_ports(),
86
+ "deleted_files": get_deleted_files(),
87
+ "top_processes": get_top_processes(),
88
+ "network_connections": get_network_connections()
89
+ }
90
+
91
+ if args.json:
92
+ print(json.dumps(results, indent=2))
93
+ else:
94
+ print("=" * 60)
95
+ print(" Open Files & Ports Audit — dargslan.com")
96
+ print("=" * 60)
97
+ print(f"\n Open files total: {results['open_file_count']}")
98
+ if results["listening_ports"]:
99
+ print(f"\n Listening ports ({len(results['listening_ports'])}):")
100
+ for p in results["listening_ports"][:8]:
101
+ print(f" {p[:80]}")
102
+ if results["top_processes"]:
103
+ print("\n Top processes by open files:")
104
+ for p in results["top_processes"][:5]:
105
+ print(f" {p['process']}: {p['count']} files")
106
+ if results["deleted_files"]:
107
+ print(f"\n Deleted but open files: {len(results['deleted_files'])}")
108
+ if results["network_connections"]:
109
+ print(f"\n Active connections: {len(results['network_connections'])}")
110
+ print("\n More tools: pip install dargslan-toolkit")
111
+ print(" eBooks: https://dargslan.com/books")
112
+
113
+ return 0
114
+
115
+
116
+ if __name__ == "__main__":
117
+ sys.exit(main())
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-lsof-audit
3
+ Version: 1.0.0
4
+ Summary: Open files and ports auditor
5
+ Author-email: Dargslan <info@dargslan.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://dargslan.com
8
+ Project-URL: Documentation, https://dargslan.com/cheat-sheets
9
+ Project-URL: Repository, https://dargslan.com/blog
10
+ Project-URL: eBook Store, https://dargslan.com/books
11
+ Keywords: linux,sysadmin,security,devops,cli,server
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: System :: Systems Administration
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+
21
+ # dargslan-lsof-audit
22
+
23
+ Audits open files, network connections, and listening ports via lsof
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install dargslan-lsof-audit
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ lsof-audit
35
+ lsof-audit --help
36
+ lsof-audit --json
37
+ ```
38
+
39
+ ## Part of Dargslan Toolkit
40
+
41
+ Install all 100+ Linux sysadmin tools:
42
+
43
+ ```bash
44
+ pip install dargslan-toolkit
45
+ ```
46
+
47
+ ## Resources
48
+
49
+ - [Dargslan eBook Store](https://dargslan.com/books) — 210+ Linux & cybersecurity eBooks
50
+ - [Linux Cheat Sheets](https://dargslan.com/cheat-sheets) — 370+ downloadable PDFs
51
+ - [Blog & Tutorials](https://dargslan.com/blog) — SEO guides and tutorials
52
+
53
+ ## License
54
+
55
+ MIT — [dargslan.com](https://dargslan.com)
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ dargslan_lsof_audit/__init__.py
4
+ dargslan_lsof_audit/cli.py
5
+ dargslan_lsof_audit.egg-info/PKG-INFO
6
+ dargslan_lsof_audit.egg-info/SOURCES.txt
7
+ dargslan_lsof_audit.egg-info/dependency_links.txt
8
+ dargslan_lsof_audit.egg-info/entry_points.txt
9
+ dargslan_lsof_audit.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lsof-audit = dargslan_lsof_audit.cli:main
@@ -0,0 +1 @@
1
+ dargslan_lsof_audit
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dargslan-lsof-audit"
7
+ version = "1.0.0"
8
+ description = "Open files and ports auditor"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.8"
12
+ authors = [{name = "Dargslan", email = "info@dargslan.com"}]
13
+ keywords = ["linux", "sysadmin", "security", "devops", "cli", "server"]
14
+ classifiers = [
15
+ "Development Status :: 5 - Production/Stable",
16
+ "Intended Audience :: System Administrators",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: System :: Systems Administration",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://dargslan.com"
25
+ Documentation = "https://dargslan.com/cheat-sheets"
26
+ Repository = "https://dargslan.com/blog"
27
+ "eBook Store" = "https://dargslan.com/books"
28
+
29
+ [project.scripts]
30
+ lsof-audit = "dargslan_lsof_audit.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+