Last active
June 2, 2019 17:57
-
-
Save goldyfruit/3e905dfd7f99551dfc44cfc19baa5f2d to your computer and use it in GitHub Desktop.
Qinling - Example 3
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
import json | |
from IPy import IP | |
def details(cidr="192.168.0.0/24", **kwargs): | |
network = IP(cidr) | |
version = network.version() | |
iptype = network.iptype().lower() | |
reverse = network.reverseName() | |
prefix = network.prefixlen() | |
netmask = str(network.netmask()) | |
broadcast = str(network.broadcast()) | |
length = network.len() | |
payload = {"ip_version": version, "type": iptype, "reverse": reverse, | |
"prefix": prefix, "netmask": netmask, "broadcast": broadcast, | |
"length": length, "cidr": cidr} | |
print("----------------------") | |
print("Function:", details.__name__) | |
print("JSON payload:", payload) | |
print("----------------------\n") | |
return build_json(payload) | |
def build_json(data): | |
indentation_level = 4 | |
print("----------------------") | |
print("Function:", build_json.__name__) | |
print("JSON options") | |
print(" - indentation:", indentation_level) | |
print(" - sort: yes") | |
print(json.dumps(data, sort_keys=True, indent=indentation_level)) | |
print("----------------------") | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment