示例#1
0
    def test_GetSubnet(self):
        print("test get_subnet_stats")

        self.assertEqual(
            ip_calculator.get_subnet_stats("192.168.10.0", "255.255.255.192"),
            """Address: 192.168.10.0/26\nSubnets: 4\nAddressable hosts per subnet: 62\nValid subnets: ['192.168.10.0', '192.168.10.64', '192.168.10.128', '192.168.10.192']\nBroadcast addresses: ['192.168.10.63', '192.168.10.127', '192.168.10.191', '192.168.10.255']\nFirst addresses: ['192.168.10.1', '192.168.10.65', '192.168.10.129', '192.168.10.193']\nLast addresses: ['192.168.10.62', '192.168.10.126', '192.168.10.190', '192.168.10.254']"""
        )
        self.assertEqual(
            ip_calculator.get_subnet_stats("172.16.0.0", "255.255.192.0"),
            """Address: 172.16.0.0/18\nSubnets: 4\nAddressable hosts per subnet: 16382\nValid subnets: ['172.16.0.0', '172.16.64.0', '172.16.128.0', '172.16.192.0']\nBroadcast addresses: ['172.16.63.255', '172.16.127.255', '172.16.191.255', '172.16.255.255']\nFirst addresses: ['172.16.0.1', '172.16.64.1', '172.16.128.1', '172.16.192.1']\nLast addresses: ['172.16.63.254', '172.16.127.254', '172.16.191.254', '172.16.255.254']"""
        )
        self.assertNotEqual(
            ip_calculator.get_subnet_stats("172.16.0.0", "255.255.192.0"), "")
        self.assertNotEqual(
            ip_calculator.get_subnet_stats("192.168.0.0", "255.255.255.0"),
            """Address: 192.168.0.0/26\nSubnets: 0\nAddressable hosts per subnet: 0\nValid subnets: []\nBroadcast addresses: []\nFirst addresses: []\nLast addresses: []"""
        )
示例#2
0
    def process_input():
        label = Label(outputs, text='Your Output Will appear here')
        label.grid(row=0, column=0)
        widgets.append(label)
        if r.get() == 1:
            for l in widgets:
                l.destroy()

            ip = e1.get()
            class_type, networks, hosts, firstAddress, lastAddress = ipc.get_class_stat(
                ip)
            label = Label(
                outputs,
                justify='left',
                text=
                'class: {}\nnetworks: {}\nhosts: {}\nfirst address: {}\nlast address: {}'
                .format(class_type, networks, hosts, firstAddress,
                        lastAddress))
            label.grid(row=0, column=0)
            widgets.append(label)

        if r.get() == 2:
            for l in widgets:
                l.destroy()

            ip = e1.get()
            subnet = e2.get()
            address, nets, v_host, valid_subs, b_addrs, f_addr, l_addr = ipc.get_subnet_stats(
                ip, subnet)
            label = Label(
                outputs,
                justify='left',
                text=
                "Address: {}\nSubnets: {}\nAddressable Hosts per subnet: {}\nValid Subnets: {}\nBroadcast Addresses: {}\nFirst Addresses: {}\nLast Addresses: {}"
                .format(address, nets, v_host, valid_subs, b_addrs, f_addr,
                        l_addr))
            label.grid(row=0, column=0)
            widgets.append(label)

        if r.get() == 3:
            for l in widgets:
                l.destroy()

            supernet_list = e3.get().split(",")
            print(supernet_list)
            supernet, netmask = ipc.get_supernet_stats(supernet_list)
            print(supernet, netmask)
            label = Label(outputs,
                          justify='left',
                          text="Address: {}\nNetwork Mask: {}".format(
                              supernet, netmask))
            label.grid(row=0, column=0)
            widgets.append(label)
示例#3
0
 def test_class_B_network(self):
     self.assertEqual(
         ip_calculator.get_subnet_stats("172.16.0.0", "255.255.192.0"), [
             '172.16.0.0/18', 4, 16382,
             ['172.16.0.0', '172.16.64.0', '172.16.128.0', '172.16.192.0'],
             [
                 '172.16.63.255', '172.16.127.255', '172.16.191.255',
                 '172.16.255.255'
             ],
             ['172.16.0.1', '172.16.64.1', '172.16.128.1', '172.16.192.1'],
             [
                 '172.16.63.254', '172.16.127.254', '172.16.191.254',
                 '172.16.255.254'
             ]
         ])
示例#4
0
 def test_class_C_network(self):
     self.assertEqual(
         ip_calculator.get_subnet_stats("192.168.10.0", "255.255.255.192"),
         [
             '192.168.10.0/26', 4, 62,
             [
                 '192.168.10.0', '192.168.10.64', '192.168.10.128',
                 '192.168.10.192'
             ],
             [
                 '192.168.10.63', '192.168.10.127', '192.168.10.191',
                 '192.168.10.255'
             ],
             [
                 '192.168.10.1', '192.168.10.65', '192.168.10.129',
                 '192.168.10.193'
             ],
             [
                 '192.168.10.62', '192.168.10.126', '192.168.10.190',
                 '192.168.10.254'
             ]
         ])
示例#5
0
def callback_subnet_info():
    user_input = (subnet_entry_box.get())
    ip_addr, subnet_mask = user_input.split(",")
    output = ipc.get_subnet_stats(ip_addr, subnet_mask)
    subnet_stats_output.delete("1.0", "end")
    subnet_stats_output.insert(tk.END, print_subnet_info(output))