|
Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
|
Functions | |
| _iter_log_lines (str log_dir, str filename_glob) | |
| list[dict] | extract_ips (str log_dir, str filter_path, str filename_glob='access.log *') |
| str | format_bytes (int n) |
| pd.DataFrame | get_geolocation_data (list[str] ips, str db_path) |
| None | plot_map (pd.DataFrame df, str output_file) |
| None | print_summary (list[dict] records, pd.DataFrame df, str focus_country) |
Variables | |
| str | DB_PATH = 'GeoLite2-City.mmdb' |
| str | FOCUS_COUNTRY = 'Russia' |
| list[dict] | ip_list = extract_ips(LOG_DIR, SEARCH_PATH) |
| pd.DataFrame | location_data = get_geolocation_data([r['ip'] for r in ip_list], DB_PATH) |
| str | LOG_DIR = 'nginx' |
| str | OUTPUT_IMAGE = 'ip_map.png' |
| str | SEARCH_PATH = '/yUNshbl1fOXngs4JRBkrJIFU' |
|
protected |
Yields lines from all matching log files in a directory, handling .gz transparently.
Definition at line 17 of file webtunnel.nginx.parselog.py.
Referenced by extract_ips().

| list[dict] webtunnel.extract_ips | ( | str | log_dir, |
| str | filter_path, | ||
| str | filename_glob = 'access.log*' ) |
Parses all matching log files in log_dir and returns records with IP and bytes transferred.
Definition at line 34 of file webtunnel.nginx.parselog.py.
References _iter_log_lines().

| str webtunnel.format_bytes | ( | int | n | ) |
Converts a byte count to a human-readable string.
Definition at line 8 of file webtunnel.nginx.parselog.py.
| pd.DataFrame webtunnel.get_geolocation_data | ( | list[str] | ips, |
| str | db_path ) |
Resolves IPs to (lat, lon) using the MaxMind database.
Definition at line 48 of file webtunnel.nginx.parselog.py.
| None webtunnel.plot_map | ( | pd.DataFrame | df, |
| str | output_file ) |
Plots the coordinates on a world map.
Definition at line 137 of file webtunnel.nginx.parselog.py.
| None webtunnel.print_summary | ( | list[dict] | records, |
| pd.DataFrame | df, | ||
| str | focus_country ) |
Prints summary statistics to the console.
Definition at line 70 of file webtunnel.nginx.parselog.py.
| str webtunnel.DB_PATH = 'GeoLite2-City.mmdb' |
Definition at line 163 of file webtunnel.nginx.parselog.py.
| str webtunnel.FOCUS_COUNTRY = 'Russia' |
Definition at line 166 of file webtunnel.nginx.parselog.py.
| list[dict] webtunnel.ip_list = extract_ips(LOG_DIR, SEARCH_PATH) |
Definition at line 169 of file webtunnel.nginx.parselog.py.
| pd.DataFrame webtunnel.location_data = get_geolocation_data([r['ip'] for r in ip_list], DB_PATH) |
Definition at line 173 of file webtunnel.nginx.parselog.py.
| str webtunnel.LOG_DIR = 'nginx' |
Definition at line 162 of file webtunnel.nginx.parselog.py.
| str webtunnel.OUTPUT_IMAGE = 'ip_map.png' |
Definition at line 165 of file webtunnel.nginx.parselog.py.
| str webtunnel.SEARCH_PATH = '/yUNshbl1fOXngs4JRBkrJIFU' |
Definition at line 164 of file webtunnel.nginx.parselog.py.