Created
July 28, 2015 13:44
-
-
Save gocreating/9d77c9cb3ce61a0a93ee to your computer and use it in GitHub Desktop.
This file contains 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
class SubnetForm(forms.Form): | |
# ...略 | |
@staticmethod | |
def int_to_human(address): | |
# ...略 | |
return ".".join(str(int(part.ljust(8, "0"), 2)) for part in parts) | |
def get_network_information(self): | |
return ({ | |
"address": self.int_to_human(address), | |
"broadcast": self.int_to_human(broadcast), | |
"cidr": cidr, | |
"first_host": self.int_to_human(first_host), | |
"last_host": self.int_to_human(last_host), | |
"network": self.int_to_human(network), | |
"num_hosts": num_hosts, | |
}) |
This file contains 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
from .forms import SubnetForm | |
@login_required | |
def ip_use_count(request): | |
form = SubnetForm(request.POST) | |
first_host = form.get_network_information().values()[6] | |
last_host = form.get_network_information().values()[2] | |
subnet_id = form.get_network_information().values()[0] | |
broadcast = form.get_network_information().values()[1] | |
cidr = form.get_network_information().values()[4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment