Last active
December 7, 2025 15:01
-
-
Save serrasqueiro/da5fbad7916863a78b75f6a7023bc779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Byte-compiled / optimized / DLL files | |
| __pycache__/ | |
| *.py[codz] | |
| *$py.class | |
| # C extensions | |
| *.so | |
| # Distribution / packaging | |
| .Python | |
| build/ | |
| develop-eggs/ | |
| dist/ | |
| downloads/ | |
| eggs/ | |
| .eggs/ | |
| lib/ | |
| lib64/ | |
| parts/ | |
| sdist/ | |
| var/ | |
| wheels/ | |
| share/python-wheels/ | |
| *.egg-info/ | |
| .installed.cfg | |
| *.egg | |
| MANIFEST | |
| # PyInstaller | |
| # Usually these files are written by a python script from a template | |
| # before PyInstaller builds the exe, so as to inject date/other infos into it. | |
| *.manifest | |
| *.spec | |
| # Installer logs | |
| pip-log.txt | |
| pip-delete-this-directory.txt | |
| # Unit test / coverage reports | |
| htmlcov/ | |
| .tox/ | |
| .nox/ | |
| .coverage | |
| .coverage.* | |
| .cache | |
| nosetests.xml | |
| coverage.xml | |
| *.cover | |
| *.py.cover | |
| .hypothesis/ | |
| .pytest_cache/ | |
| cover/ | |
| # Translations | |
| *.mo | |
| *.pot | |
| # Django stuff: | |
| *.log | |
| local_settings.py | |
| db.sqlite3 | |
| db.sqlite3-journal | |
| # Flask stuff: | |
| instance/ | |
| .webassets-cache | |
| # Scrapy stuff: | |
| .scrapy | |
| # Sphinx documentation | |
| docs/_build/ | |
| # PyBuilder | |
| .pybuilder/ | |
| target/ | |
| # Jupyter Notebook | |
| .ipynb_checkpoints | |
| # IPython | |
| profile_default/ | |
| ipython_config.py | |
| # pyenv | |
| # For a library or package, you might want to ignore these files since the code is | |
| # intended to run in multiple environments; otherwise, check them in: | |
| # .python-version | |
| # pipenv | |
| # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | |
| # However, in case of collaboration, if having platform-specific dependencies or dependencies | |
| # having no cross-platform support, pipenv may install dependencies that don't work, or not | |
| # install all needed dependencies. | |
| #Pipfile.lock | |
| # UV | |
| # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. | |
| # This is especially recommended for binary packages to ensure reproducibility, and is more | |
| # commonly ignored for libraries. | |
| #uv.lock | |
| # poetry | |
| # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | |
| # This is especially recommended for binary packages to ensure reproducibility, and is more | |
| # commonly ignored for libraries. | |
| # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | |
| #poetry.lock | |
| #poetry.toml | |
| # pdm | |
| # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | |
| # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. | |
| # https://pdm-project.org/en/latest/usage/project/#working-with-version-control | |
| #pdm.lock | |
| #pdm.toml | |
| .pdm-python | |
| .pdm-build/ | |
| # pixi | |
| # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. | |
| #pixi.lock | |
| # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one | |
| # in the .venv directory. It is recommended not to include this directory in version control. | |
| .pixi | |
| # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | |
| __pypackages__/ | |
| # Celery stuff | |
| celerybeat-schedule | |
| celerybeat.pid | |
| # SageMath parsed files | |
| *.sage.py | |
| # Environments | |
| .env | |
| .envrc | |
| .venv | |
| env/ | |
| venv/ | |
| ENV/ | |
| env.bak/ | |
| venv.bak/ | |
| # Spyder project settings | |
| .spyderproject | |
| .spyproject | |
| # Rope project settings | |
| .ropeproject | |
| # mkdocs documentation | |
| /site | |
| # mypy | |
| .mypy_cache/ | |
| .dmypy.json | |
| dmypy.json | |
| # Pyre type checker | |
| .pyre/ | |
| # pytype static type analyzer | |
| .pytype/ | |
| # Cython debug symbols | |
| cython_debug/ | |
| # PyCharm | |
| # JetBrains specific template is maintained in a separate JetBrains.gitignore that can | |
| # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | |
| # and can be added to the global gitignore or merged into this file. For a more nuclear | |
| # option (not recommended) you can uncomment the following to ignore the entire idea folder. | |
| #.idea/ | |
| # Abstra | |
| # Abstra is an AI-powered process automation framework. | |
| # Ignore directories containing user credentials, local state, and settings. | |
| # Learn more at https://abstra.io/docs | |
| .abstra/ | |
| # Visual Studio Code | |
| # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore | |
| # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore | |
| # and can be added to the global gitignore or merged into this file. However, if you prefer, | |
| # you could uncomment the following to ignore the entire vscode folder | |
| # .vscode/ | |
| # Ruff stuff: | |
| .ruff_cache/ | |
| # PyPI configuration file | |
| .pypirc | |
| # Cursor | |
| # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to | |
| # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data | |
| # refer to https://docs.cursor.com/context/ignore-files | |
| .cursorignore | |
| .cursorindexingignore | |
| # Marimo | |
| marimo/_static/ | |
| marimo/_lsp/ | |
| __marimo__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .pylintrc | |
| [MASTER] | |
| extension-pkg-whitelist=wmi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ winpy -- Generic Window-zed package | |
| """ | |
| WINPY_VERSION = "1.00 12" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ Generated by copilot but beautified by myself. | |
| - Q#1: isn't there a realiable python script for me to dump what are | |
| the physical ethernet interfaces and my wifi interfaces? | |
| + ...instead of `C:/Users/henrique>netsh interface ip show config` | |
| """ | |
| # pylint: disable=missing-function-docstring | |
| import json | |
| import socket | |
| import psutil | |
| def main(): | |
| list_them() | |
| def list_them(): | |
| """ List my interfaces. """ | |
| res = get_my_interfaces() | |
| print(tostring(res)) | |
| own, virtual = res["own"], res["virtual"] | |
| print(f'### own (len={len(own)}):') # Lists own interfaces | |
| for idx, key in enumerate(sorted(own), 1): | |
| print(f"### ({idx}/{len(own)}):", key, resume(own[key]), end="\n\n") | |
| if virtual: | |
| print("### box:", sorted(res["virtual"])) | |
| return res | |
| def get_interfaces(): | |
| """ Wrapper to get network interfaces! """ | |
| return get_my_interfaces() | |
| def get_my_interfaces(): | |
| """ Retrieve my interfaces. """ | |
| interfaces = {} | |
| addrs = psutil.net_if_addrs() | |
| stats = psutil.net_if_stats() | |
| for iface, addr_list in addrs.items(): | |
| iface_info = { | |
| "type": classify_interface(iface), | |
| "is_up": stats[iface].isup, | |
| "speed_mbps": stats[iface].speed, | |
| "addresses": [], | |
| } | |
| for addr in addr_list: | |
| iface_info["addresses"].append(itemized(addr)) | |
| interfaces[iface] = iface_info | |
| res = split_ifs(interfaces) | |
| return res | |
| def classify_interface(name): | |
| """ Major (lan/ wifi) Interface Classification """ | |
| if "Wi-Fi" in name or "Wireless" in name: | |
| return "wifi" | |
| if "Ethernet" in name: | |
| return "ethernet" | |
| return "other" | |
| def itemized(addr): | |
| """ Returns a dictionary based information. """ | |
| def family_iface(family): | |
| return family_name(family) | |
| item = { | |
| "family": family_iface(addr.family), # AddressFamily(addr.family) for -1 does not work | |
| "address": addr.address, | |
| "netmask": addr.netmask, | |
| "broadcast": addr.broadcast | |
| } | |
| return item | |
| def family_name(fam): | |
| """ Return human-readable family name for an address family integer. """ | |
| assert isinstance(fam, int), f"Bogus family (listed): {[fam]}" | |
| fam_name = getattr(socket, "AddressFamily") | |
| if fam_name is not None: | |
| return "AF_LINK" if fam == -1 else fam_name(fam).name | |
| if fam == socket.AF_INET: | |
| astr = "AF_INET" | |
| elif fam == socket.AF_INET6: | |
| astr = "AF_INET6" | |
| else: | |
| astr = str(fam) | |
| return astr | |
| def resume(ifc, def_str="-"): | |
| """ Returns the listed addresses of an interface. """ | |
| lst = ifc.get("addresses") | |
| if lst is None: | |
| return def_str | |
| # sample_str = f"(len={len(lst)}) <" + repr(["FIRST"] + lst + ["LAST"]) + ">" | |
| return lst | |
| def split_ifs(interfaces): | |
| own = {} | |
| virtual = {} | |
| for name, info in interfaces.items(): | |
| is_virtual = False | |
| # Check IP addresses for VirtualBox host-only range | |
| for addr in info.get("addresses", []): | |
| ip = addr.get("address", "") | |
| if ip.startswith("192.168.56."): | |
| is_virtual = True | |
| break | |
| if is_virtual: | |
| virtual[name] = info | |
| else: | |
| own[name] = info | |
| res = {"own": own, "virtual": virtual} | |
| return res | |
| def tostring(obj): | |
| """ Returns the JSON equivalent """ | |
| astr = json.dumps(obj, indent=4) | |
| return astr | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| lanresume.py | |
| Command-line tool to summarize network interfaces using winpy.lanman. | |
| Supports filtering by --wifi, --ethernet, --virtual-box | |
| """ | |
| import argparse | |
| import sys | |
| import os.path | |
| sys.path.append(os.path.dirname(__file__)) | |
| import winpy.lanman | |
| def main(argv=None): | |
| """Main entry point.""" | |
| code, _, _ = script(sys.argv[1:]) | |
| return code | |
| def script(argv): | |
| args = parse_args(argv) | |
| interfaces = winpy.lanman.get_interfaces() | |
| filtered = filter_interfaces(interfaces, args) | |
| #for name, info in filtered.items(): print(f"{name}: {info}") | |
| list_them(filtered) | |
| return 0, interfaces, filtered | |
| def list_them(ifs, sep=None): | |
| line_sep = "---\n" if sep is None else "\n" | |
| for name in sorted(ifs): | |
| here = ifs[name] | |
| print(f"{name} ({len(here)})", end=(":\n" if here else "\n")) | |
| for key in sorted(here): | |
| item = here[key] | |
| print(" " * 3, key, item, end="\n\n") | |
| print(end=line_sep) | |
| def parse_args(argv): | |
| """Parse command-line arguments.""" | |
| parser = argparse.ArgumentParser( | |
| description="Summarize network interfaces (Wi-Fi, Ethernet, VirtualBox)." | |
| ) | |
| parser.add_argument( | |
| "--wifi", | |
| action="store_true", | |
| help="Show only Wi-Fi interfaces" | |
| ) | |
| parser.add_argument( | |
| "--ethernet", | |
| action="store_true", | |
| help="Show only Ethernet interfaces" | |
| ) | |
| parser.add_argument( | |
| "--virtual-box", | |
| action="store_true", | |
| help="Show only VirtualBox interfaces" | |
| ) | |
| return parser.parse_args(argv) | |
| def filter_interfaces(interfaces, args): | |
| """Filter interfaces based on command-line options.""" | |
| result = {} | |
| for name, info in interfaces.items(): | |
| desc = info.get("caption", "") or info.get("description", "") or name | |
| if args.wifi and "Wi-Fi" in desc: | |
| result[name] = info | |
| elif args.ethernet and "Ethernet" in desc: | |
| result[name] = info | |
| elif args.virtual_box and "VirtualBox" in desc: | |
| result[name] = info | |
| elif not (args.wifi or args.ethernet or args.virtual_box): | |
| # No filter specified → include all | |
| result[name] = info | |
| return result | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MIT License | |
| Copyright (c) 2025 Henrique | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all | |
| copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ Generated by copilot but beautified by myself. | |
| Microsoft Adapters 'wmi' -- WMI is Windows Management Instrumentation. | |
| """ | |
| import wmi # pylint: disable=import-error | |
| def main(): | |
| """Main entry point: collect adapters and classify them.""" | |
| adapters = get_adapter_descriptions() | |
| result = split_ifs(adapters) | |
| print(result) | |
| def get_adapter_descriptions(): | |
| """Return a dictionary of network adapters keyed by description with basic info.""" | |
| c = wmi.WMI() | |
| adapters = {} | |
| for nic in c.Win32_NetworkAdapterConfiguration(IPEnabled=True): | |
| adapters[nic.Description] = { | |
| "caption": nic.Caption, | |
| "mac": nic.MACAddress, | |
| "ip": nic.IPAddress, | |
| "dns": nic.DNSDomain, | |
| } | |
| return adapters | |
| def split_ifs(adapters): | |
| """Split adapters into 'own' and 'virtual' groups based on description.""" | |
| own = {} | |
| virtual = {} | |
| for desc, info in adapters.items(): | |
| if "VirtualBox" in desc: | |
| virtual[desc] = info | |
| else: | |
| own[desc] = info | |
| return {"own": own, "virtual": virtual} | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ Generated by copilot | |
| - "what is a reliable windows 11 substitute of Linux 'tail' executable?" | |
| -- Copilot gave me a Powershell script | |
| - "i hate powershell, give me instead a python script to run" | |
| - "name == 'main' should have only main(), nothing else." | |
| - "why is [n] exactly?" | |
| - "well, arguments should be arranged in a robust way" | |
| - "show me my prompts" | |
| - "sure, good, but no UTF-8 chars for quotes please, regular ASCII" | |
| """ | |
| import argparse | |
| import time | |
| import os | |
| def tail(filename, n=10, follow=False): | |
| """Print the last n lines of a file, optionally follow new lines.""" | |
| with open(filename, "r", encoding="utf-8", errors="ignore") as f: | |
| # Go to end of file | |
| f.seek(0, os.SEEK_END) | |
| filesize = f.tell() | |
| # Read backwards until we have n lines | |
| blocksize = 1024 | |
| data = "" | |
| while filesize > 0 and data.count("\n") <= n: | |
| readsize = min(blocksize, filesize) | |
| filesize -= readsize | |
| f.seek(filesize) | |
| data = f.read(readsize) + data | |
| lines = data.splitlines()[-n:] | |
| for line in lines: | |
| print(line) | |
| if follow: | |
| while True: | |
| line = f.readline() | |
| if line: | |
| print(line, end="") | |
| else: | |
| time.sleep(0.5) | |
| def main(): | |
| """ Main script! """ | |
| parser = argparse.ArgumentParser( | |
| description="Python implementation of tail (last lines of a file)." | |
| ) | |
| parser.add_argument( | |
| "filename", | |
| help="Path to the file to read" | |
| ) | |
| parser.add_argument( | |
| "-n", "--lines", | |
| type=int, | |
| default=10, | |
| help="Number of lines to show (default: 10)" | |
| ) | |
| parser.add_argument( | |
| "-f", "--follow", | |
| action="store_true", | |
| help="Keep reading the file as it grows (like tail -f)" | |
| ) | |
| args = parser.parse_args() | |
| tail(args.filename, n=args.lines, follow=args.follow) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment