-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (53 loc) · 1.81 KB
/
Copy pathmain.py
File metadata and controls
66 lines (53 loc) · 1.81 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
#!/usr/bin/env python3
"""TelePiHomeReconBot - Entry Point"""
import sys
import argparse
import logging
import json
from pathlib import Path
BASE_DIR = Path(__file__).parent
sys.path.insert(0, str(BASE_DIR / "src"))
from dotenv import load_dotenv
from storage.device_db import DeviceDB
from scanner.nmap_scanner import NmapScanner
from bot import TelegramBot
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def load_config():
config_path = BASE_DIR / "config" / "config.json"
with open(config_path) as f:
return json.load(f)
def load_env():
env_path = BASE_DIR / ".env"
if env_path.exists():
load_dotenv(env_path)
else:
logger.warning("[!] .env not found."
"\nRename .env.example into .env."
"\nPut your Telegram Bot token and authorized user ID in it.")
def main():
parser = argparse.ArgumentParser(description='TelePiHomeReconBot')
parser.add_argument('--bot', action='store_true', help='Run Telegram bot')
parser.add_argument('--scan', action='store_true', help='Run single scan')
args = parser.parse_args()
load_env()
config = load_config()
if args.bot:
logger.info("Starting Telegram bot...")
db = DeviceDB(BASE_DIR / "db.sqlite")
scanner = NmapScanner(config['scanner']['nmap_args'])
bot = TelegramBot(db, scanner, config)
bot.run()
elif args.scan:
logger.info("Running a single scan...")
scanner = NmapScanner(config['scanner']['nmap_args'])
devices = scanner.scan()
for d in devices:
logger.info(f" {d['ip']} - {d['mac']} - {d.get('hostname', 'N/A')}")
else:
parser.print_help()
if __name__ == "__main__":
main()