-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinpoint
More file actions
executable file
·400 lines (345 loc) · 13.5 KB
/
Copy pathpinpoint
File metadata and controls
executable file
·400 lines (345 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/usr/bin/env python3
"""
Network Pinpointer - Enhanced CLI with Quality of Life Improvements
A network diagnostic tool using LJPW semantic framework for
intelligent network analysis and troubleshooting.
Usage:
pinpoint interactive # Start interactive mode
pinpoint quick-check [target] # Quick 30s health check
pinpoint ping <target> # Enhanced ping with analysis
pinpoint run <recipe> # Run diagnostic recipe
pinpoint health # Show network health
pinpoint explain <topic> # Explain LJPW dimensions
pinpoint recipes # List available recipes
"""
import sys
import argparse
from typing import Optional
from network_pinpointer.cli_output import get_formatter, print_error, print_info
from network_pinpointer.quick_commands import QuickCommands
from network_pinpointer.interactive_mode import InteractiveMode
from network_pinpointer.diagnostic_recipes import RecipeLibrary
from network_pinpointer.diff_mode import DiffAnalyzer
from network_pinpointer.patterns import PatternLibrary
from network_pinpointer.watch_mode import WatchMode
from network_pinpointer.history import HistoryManager
from network_pinpointer.export import Exporter
from network_pinpointer.config import get_config
class NetworkPinpointerCLI:
"""Main CLI application"""
def __init__(self):
self.fmt = get_formatter()
self.quick = QuickCommands()
self.library = RecipeLibrary()
self.differ = DiffAnalyzer()
self.pattern_lib = PatternLibrary()
self.history = HistoryManager()
self.exporter = Exporter()
def run(self, args=None):
"""Run the CLI application"""
parser = self.create_parser()
parsed_args = parser.parse_args(args)
# Handle commands
if parsed_args.command == 'interactive':
self.run_interactive()
elif parsed_args.command == 'quick-check':
self.run_quick_check(parsed_args.target)
elif parsed_args.command == 'ping':
self.run_ping(parsed_args.target, parsed_args.count)
elif parsed_args.command == 'run':
self.run_recipe(parsed_args.recipe, parsed_args.target)
elif parsed_args.command == 'health':
self.run_health()
elif parsed_args.command == 'explain':
self.run_explain(parsed_args.topic)
elif parsed_args.command == 'recipes':
self.list_recipes()
elif parsed_args.command == 'patterns':
self.show_patterns()
elif parsed_args.command == 'diff':
self.run_diff(parsed_args.before, parsed_args.after)
elif parsed_args.command == 'watch':
self.run_watch(parsed_args.targets, parsed_args.interval)
elif parsed_args.command == 'history':
self.run_history(parsed_args.target, parsed_args.hours, parsed_args.dimension)
elif parsed_args.command == 'export':
self.run_export(parsed_args.input, parsed_args.format)
elif parsed_args.command == 'config':
self.run_config(parsed_args.action)
elif parsed_args.command == 'setup':
self.run_setup()
elif parsed_args.command == 'version':
self.show_version()
else:
parser.print_help()
def create_parser(self) -> argparse.ArgumentParser:
"""Create argument parser"""
parser = argparse.ArgumentParser(
prog='pinpoint',
description='Network diagnostic tool using LJPW semantic framework',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
pinpoint interactive # Start interactive mode
pinpoint quick-check 8.8.8.8 # Quick health check
pinpoint ping api.example.com # Enhanced ping
pinpoint run slow_connection # Run diagnostic recipe
pinpoint health # Show network health
pinpoint explain love # Learn about Love dimension
For more information, visit: https://github.com/BruinGrowly/Network-Pinpointer
"""
)
subparsers = parser.add_subparsers(dest='command', help='Command to run')
# Interactive mode
subparsers.add_parser(
'interactive',
help='Start interactive diagnostic mode'
)
# Quick check
quick_check_parser = subparsers.add_parser(
'quick-check',
help='Quick 30-second network health check'
)
quick_check_parser.add_argument(
'target',
nargs='?',
default='8.8.8.8',
help='Target IP or hostname (default: 8.8.8.8)'
)
# Enhanced ping
ping_parser = subparsers.add_parser(
'ping',
help='Enhanced ping with semantic analysis'
)
ping_parser.add_argument(
'target',
help='Target IP or hostname'
)
ping_parser.add_argument(
'-c', '--count',
type=int,
default=10,
help='Number of packets (default: 10)'
)
# Run recipe
run_parser = subparsers.add_parser(
'run',
help='Run a diagnostic recipe'
)
run_parser.add_argument(
'recipe',
choices=[
'slow_connection',
'cant_connect',
'intermittent',
'security_audit',
'baseline',
'quick_check'
],
help='Recipe to run'
)
run_parser.add_argument(
'target',
nargs='?',
default='8.8.8.8',
help='Target IP or hostname (default: 8.8.8.8)'
)
# Health status
subparsers.add_parser(
'health',
help='Show current network health status'
)
# Explain
explain_parser = subparsers.add_parser(
'explain',
help='Explain LJPW dimensions or concepts'
)
explain_parser.add_argument(
'topic',
nargs='?',
default='ljpw',
help='Topic to explain (love, justice, power, wisdom, ljpw)'
)
# List recipes
subparsers.add_parser(
'recipes',
help='List available diagnostic recipes'
)
# Patterns
subparsers.add_parser(
'patterns',
help='Show library of known network patterns'
)
# Diff/Compare
diff_parser = subparsers.add_parser(
'diff',
help='Compare two network states'
)
diff_parser.add_argument('before', help='Before state file (JSON)')
diff_parser.add_argument('after', help='After state file (JSON)')
# Watch mode
watch_parser = subparsers.add_parser(
'watch',
help='Continuously monitor network targets'
)
watch_parser.add_argument('targets', nargs='+', help='Targets to monitor')
watch_parser.add_argument('-i', '--interval', type=int, default=300,
help='Check interval in seconds (default: 300)')
# History
history_parser = subparsers.add_parser(
'history',
help='View historical network data'
)
history_parser.add_argument('target', help='Target to view history for')
history_parser.add_argument('--hours', type=int, default=24,
help='Hours of history to show (default: 24)')
history_parser.add_argument('--dimension', choices=['love', 'justice', 'power', 'wisdom'],
help='Dimension to plot (default: health score)')
# Export
export_parser = subparsers.add_parser(
'export',
help='Export results to file'
)
export_parser.add_argument('input', help='Input file to export')
export_parser.add_argument('-f', '--format', choices=['json', 'html', 'markdown'],
default='html', help='Export format (default: html)')
# Config
config_parser = subparsers.add_parser(
'config',
help='Manage configuration'
)
config_parser.add_argument('action', choices=['show', 'create-example'],
help='Config action')
# Setup wizard
subparsers.add_parser(
'setup',
help='Run the interactive setup wizard'
)
# Version
subparsers.add_parser(
'version',
help='Show version information'
)
return parser
def run_interactive(self):
"""Run interactive mode"""
try:
interactive = InteractiveMode()
interactive.run()
except KeyboardInterrupt:
print("\n" + self.fmt.info("Interrupted by user. Goodbye!"))
sys.exit(0)
def run_quick_check(self, target: str):
"""Run quick health check"""
success = self.quick.quick_check(target)
sys.exit(0 if success else 1)
def run_ping(self, target: str, count: int):
"""Run enhanced ping"""
if not target:
print_error("Target is required for ping command")
print_info("Usage: pinpoint ping <target>")
sys.exit(1)
success = self.quick.enhanced_ping(target, count)
sys.exit(0 if success else 1)
def run_recipe(self, recipe_name: str, target: str):
"""Run a diagnostic recipe"""
recipe = self.library.get_recipe(recipe_name)
if not recipe:
print_error(f"Recipe '{recipe_name}' not found")
print_info("Run 'pinpoint recipes' to see available recipes")
sys.exit(1)
# Show plan
print(recipe.display_plan())
# For now, run simplified version via interactive mode
interactive = InteractiveMode()
interactive.execute_recipe(recipe, target)
def run_health(self):
"""Show health status"""
self.quick.show_health()
def run_explain(self, topic: str):
"""Explain a topic"""
self.quick.explain(topic)
def list_recipes(self):
"""List all available recipes"""
print(self.library.display_all_recipes())
def show_patterns(self):
"""Show pattern library"""
print(self.pattern_lib.display_all_patterns())
def run_diff(self, before_file: str, after_file: str):
"""Compare two network states"""
from pathlib import Path
analysis = self.differ.compare_files(Path(before_file), Path(after_file))
print(self.differ.display_comparison(analysis))
def run_watch(self, targets: list, interval: int):
"""Run watch mode"""
watcher = WatchMode(targets, interval)
watcher.start()
def run_history(self, target: str, hours: int, dimension: Optional[str]):
"""Show historical data"""
timeline = self.history.generate_timeline(target, hours, dimension)
print(timeline)
def run_export(self, input_file: str, format: str):
"""Export results"""
print(f"Exporting {input_file} to {format}...")
print("Export feature implementation in progress")
def run_config(self, action: str):
"""Manage configuration"""
if action == 'show':
config = get_config()
print(self.fmt.section_header("Current Configuration"))
print(f"Network Type: {config.network_type}")
print(f"Monitoring Interval: {config.monitoring_interval}s")
print(f"Output Format: {config.output.format}")
print(f"Colors: {config.output.colors}")
elif action == 'create-example':
from network_pinpointer.config import ConfigManager
from pathlib import Path
manager = ConfigManager()
path = Path.home() / ".network-pinpointer" / "config.yaml"
manager.create_example_config(path)
def run_setup(self):
"""Run the setup wizard"""
from network_pinpointer.first_run import FirstRunExperience
experience = FirstRunExperience()
experience.run()
def show_version(self):
"""Show version information"""
print(self.fmt.section_header("Network Pinpointer"))
print("""
Version: 1.0.0
LJPW Semantic Framework for Network Diagnostics
Components:
• Real Packet Capture
• Semantic Analysis Engine
• Holistic Health Tracking
• Root Cause Prioritization
• Interactive Diagnostic Mode
Copyright (c) 2025
License: MIT
""")
def main():
"""Main entry point"""
try:
# Skip first-run experience for help/version commands
skip_first_run_args = {'--help', '-h', '--version', '-V', 'help', 'version'}
should_skip_first_run = any(arg in skip_first_run_args for arg in sys.argv[1:])
if not should_skip_first_run:
# Check for first run and show welcoming experience
# (Love principle: warm greeting for new users)
from network_pinpointer.first_run import run_first_run_if_needed
run_first_run_if_needed()
cli = NetworkPinpointerCLI()
cli.run()
except KeyboardInterrupt:
print("\n\nInterrupted by user. Goodbye!")
sys.exit(0)
except Exception as e:
import traceback
print(f"\n{get_formatter().error('An error occurred:')}")
print(f"{e}")
if '--debug' in sys.argv:
print("\nDebug traceback:")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()