https://github.com/marcelcoding/docker-network-viewer
Liste docker networks and according subnet.
https://github.com/marcelcoding/docker-network-viewer
Last synced: 6 months ago
JSON representation
Liste docker networks and according subnet.
- Host: GitHub
- URL: https://github.com/marcelcoding/docker-network-viewer
- Owner: MarcelCoding
- Created: 2021-08-11T18:36:13.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-05T16:32:21.000Z (over 3 years ago)
- Last Synced: 2025-02-08T04:46:44.288Z (8 months ago)
- Language: Go
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Docker Network Viewer
Liste docker networks and according subnet.
## Setup
1. Setup my Debian Repository: [deb.m4rc3l.de](https://deb.m4rc3l.de/)
2. `sudo apt install docker-network-viewer`
3. Run `dnv` or `docker-network-viewer`## Credits
This replaces the old script `dnv.py`, witten by [@felbinger](https://github.com/felbinger).
He also had a Go version that was no longer maintained.```python
#!/usr/bin/python3.8from docker import from_env as docker_env
from prettytable import PrettyTable
from os import geteuiddef get_networks():
networks = list()
for network in docker_env().networks.list():
if network:
config = network.attrs.get('IPAM').get('Config')
subnet = config[0].get('Subnet') if len(config) else None
if subnet:
networks.append([
network.attrs.get('Name'),
subnet
])
return networksif __name__ == "__main__":
if geteuid() != 0:
print("Please run the script as root!")
exit(1)networks = sorted(get_networks(), key=lambda ip: list(map(int, ip[1].split("/")[0].split("."))))
table = PrettyTable()
table.field_names = ["Name", "Subnet"]
for row in networks:
table.add_row(row)table.align['Name'] = 'l'
table.align['Subnet'] = 'l'
print(table)
```