Example #1
0
    def __init__(self):
        self.subnet = Subnet()

        self.total = Tk()
        self.total.wm_title('Total Host Count Calculator')

        self.count_from_cidr = LabelFrame(
            self.total, text='Total Host Count: CIDR Address')
        self.cidr_label = Label(self.count_from_cidr,
                                text='CIDR Address:',
                                width=20)
        self.cidr_entry = Entry(self.count_from_cidr, width=25)

        self.count_from_netmask = LabelFrame(self.total,
                                             text='Total Host Count: Netmask')
        self.netmask_label = Label(self.count_from_netmask,
                                   text='Netmask:',
                                   width=20)
        self.netmask_entry = Entry(self.count_from_netmask, width=25)

        self.count_from_ip_range = LabelFrame(
            self.total, text='Total Host Count: Assignable IP Range')
        self.ip_range_label = Label(self.count_from_ip_range,
                                    text='Assignable IP Range:',
                                    width=20)
        self.ip_range_entry = Entry(self.count_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.total, text='Learning Steps')

        self.calculate = Button(self.count_from_cidr,
                                text='Calculate',
                                command=lambda: self.get_count_from_cidr())
        self.calculate2 = Button(self.count_from_netmask,
                                 text='Calculate',
                                 command=lambda: self.get_count_from_netmask())
        self.calculate3 = Button(
            self.count_from_ip_range,
            text='Calculate',
            command=lambda: self.get_count_from_ip_range())

        self.count_from_cidr.grid(row=0)
        self.count_from_netmask.grid(row=1)
        self.count_from_ip_range.grid(row=2)
        self.learning_steps.grid(row=3, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.netmask_label.grid(row=0, column=0, sticky='W')
        self.netmask_entry.grid(row=0, column=1)
        self.calculate2.grid(row=0, column=2)

        self.ip_range_label.grid(row=0, column=0, sticky='W')
        self.ip_range_entry.grid(row=0, column=1)
        self.calculate3.grid(row=0, column=2)

        # self.total.mainloop()
        pass
 def test_general_calculation_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.general_calculation()
     self.assertEqual(test_subnet.cidr_address, '152.2.136.0/26')
     self.assertEqual(test_subnet.netmask, '255.255.255.192')
     self.assertEqual(test_subnet.network_address, '152.2.136.0')
     self.assertEqual(test_subnet.broadcast_address, '152.2.136.63')
     # self.assertEqual(test_subnet.ip_range, '152.2.136.1-152.2.136.62')
     self.assertEqual(test_subnet.total_host_count, 64)
     self.assertEqual(test_subnet.assignable_host_count, 62)
Example #3
0
    def __init__(self):
        self.subnet = Subnet()

        self.general_calculator = Tk()
        self.general_calculator.wm_title('General Subnet Calculator')

        self.cidr_label = Label(self.general_calculator, text='CIDR Address:')
        self.network_label = Label(self.general_calculator,
                                   text='Network Address:')
        self.netmask_label = Label(self.general_calculator, text='Netmask:')
        self.broadcast_label = Label(self.general_calculator,
                                     text='Broadcast Address:')
        self.ip_range_label = Label(self.general_calculator,
                                    text='Assignable IP Range:')
        self.total_host_label = Label(self.general_calculator,
                                      text='Total Host Count:')
        self.assignable_host_label = Label(self.general_calculator,
                                           text='Assignable Host Count:')

        self.cidr_entry = Entry(self.general_calculator, width=25)
        self.network_entry = Entry(self.general_calculator, width=25)
        self.netmask_entry = Entry(self.general_calculator, width=25)
        self.broadcast_entry = Entry(self.general_calculator, width=25)
        self.ip_range_entry = Entry(self.general_calculator, width=25)
        self.total_host_entry = Entry(self.general_calculator, width=25)
        self.assignable_host_entry = Entry(self.general_calculator, width=25)

        self.calculate = Button(self.general_calculator,
                                text='Calculate',
                                command=lambda: self.get_entries())

        self.cidr_label.grid(row=0, column=0, sticky='E')
        self.network_label.grid(row=1, column=0, sticky='E')
        self.netmask_label.grid(row=2, column=0, sticky='E')
        self.broadcast_label.grid(row=3, column=0, sticky='E')
        self.ip_range_label.grid(row=4, column=0, sticky='E')
        self.total_host_label.grid(row=5, column=0, sticky='E')
        self.assignable_host_label.grid(row=6, column=0, sticky='E')

        self.cidr_entry.grid(row=0, column=1)
        self.network_entry.grid(row=1, column=1)
        self.netmask_entry.grid(row=2, column=1)
        self.broadcast_entry.grid(row=3, column=1)
        self.ip_range_entry.grid(row=4, column=1)
        self.total_host_entry.grid(row=5, column=1)
        self.assignable_host_entry.grid(row=6, column=1)

        self.calculate.grid(row=7, columnspan=2)
Example #4
0
    def __init__(self):
        self.subnet = Subnet()

        self.cidr = Tk()
        self.cidr.wm_title('CIDR Calculator')

        self.cidr_from_netmask = LabelFrame(
            self.cidr, text='CIDR: Network Address & Netmask')
        self.net_address_label = Label(self.cidr_from_netmask,
                                       text='Network Address:')
        self.netmask_label = Label(self.cidr_from_netmask, text='Netmask:')
        self.net_address_entry = Entry(self.cidr_from_netmask, width=25)
        self.netmask_entry = Entry(self.cidr_from_netmask, width=25)

        self.cidr_from_ip_range = LabelFrame(
            self.cidr, text='CIDR: Network Address & Assignable IP Range')
        self.net_address_label2 = Label(self.cidr_from_ip_range,
                                        text='Network Address:')
        self.ip_range_label = Label(self.cidr_from_ip_range,
                                    text='Assignable IP Range:')
        self.net_address_entry2 = Entry(self.cidr_from_ip_range, width=25)
        self.ip_range_entry = Entry(self.cidr_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.cidr, text='Learning Steps')

        self.calculate = Button(self.cidr_from_netmask,
                                text='Calculate',
                                command=lambda: self.get_cidr_from_netmask())
        self.calculate2 = Button(self.cidr_from_ip_range,
                                 text='Calculate',
                                 command=lambda: self.get_cidr_from_ip_range())

        self.cidr_from_netmask.grid(row=0)
        self.cidr_from_ip_range.grid(row=1)
        self.learning_steps.grid(row=2, sticky='W')

        self.net_address_label.grid(row=0, column=0, sticky='W')
        self.net_address_entry.grid(row=1, column=0)
        self.netmask_label.grid(row=0, column=1, sticky='W')
        self.netmask_entry.grid(row=1, column=1)
        self.calculate.grid(row=1, column=2)

        self.net_address_label2.grid(row=0, column=0, sticky='W')
        self.net_address_entry2.grid(row=1, column=0)
        self.ip_range_label.grid(row=0, column=1, sticky='W')
        self.ip_range_entry.grid(row=1, column=1)
        self.calculate2.grid(row=1, column=2)
 def test_reset_variables(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.network_address = '152.2.136.0'
     test_subnet.netmask = '255.255.255.192'
     test_subnet.broadcast_address = '152.2.136.63'
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.reset_variables()
     self.assertEqual(test_subnet.cidr_address, '')
     self.assertEqual(test_subnet.netmask, '')
     self.assertEqual(test_subnet.network_address, '')
     self.assertEqual(test_subnet.broadcast_address, '')
     self.assertEqual(test_subnet.ip_range, '')
     pass
    def __init__(self):
        self.subnet = Subnet()

        self.broadcast = Tk()
        self.broadcast.wm_title('Broadcast Address Calculator')

        self.broadcast_from_cidr = LabelFrame(
            self.broadcast, text='Broadcast Address: CIDR Address')
        self.cidr_label = Label(self.broadcast_from_cidr,
                                text='CIDR Address:',
                                width=20)
        self.cidr_entry = Entry(self.broadcast_from_cidr, width=25)

        self.broadcast_from_ip_range = LabelFrame(
            self.broadcast, text='Broadcast Address: Assignable IP Range')
        self.ip_range_label = Label(self.broadcast_from_ip_range,
                                    text='Assignable IP Range:',
                                    width=20)
        self.ip_range_entry = Entry(self.broadcast_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.broadcast, text='Learning Steps')

        self.calculate = Button(self.broadcast_from_cidr,
                                text='Calculate',
                                command=lambda: self.get_broadcast_from_cidr())
        self.calculate2 = Button(
            self.broadcast_from_ip_range,
            text='Calculate',
            command=lambda: self.get_broadcast_from_ip_range())

        self.broadcast_from_cidr.grid(row=0)
        self.broadcast_from_ip_range.grid(row=1)
        self.learning_steps.grid(row=2, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.ip_range_label.grid(row=0, column=0, sticky='W')
        self.ip_range_entry.grid(row=0, column=1)
        self.calculate2.grid(row=0, column=2)
 def test_calculate_total_host_count_from_cidr(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.calculate_total_host_count_from_cidr()
     self.assertEqual(test_subnet.total_host_count, 64)
 def test_calculate_ip_range_from_network_broadcast(self):
     test_subnet = Subnet()
     test_subnet.network_address = '152.2.136.0'
     test_subnet.broadcast_address = '152.2.136.63'
     test_subnet.calculate_ip_range_from_network_broadcast()
     self.assertEqual(test_subnet.ip_range, '152.2.136.1-152.2.136.62')
 def test_calculate_ip_range_from_cidr(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.calculate_ip_range_from_cidr()
     self.assertEqual(test_subnet.ip_range, '152.2.136.1-152.2.136.62')
 def test_calculate_broadcast_address_from_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.calculate_broadcast_address_from_ip_range()
     self.assertEqual(test_subnet.broadcast_address, '152.2.136.63')
 def test_verify_variables_total_host_count(self):
     test_subnet = Subnet()
     test_subnet.total_host_count = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_total_host_count())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.total_host_count = '123'
     self.assertFalse(test_subnet.verify_total_host_count())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.total_host_count = '64'
     self.assertTrue(test_subnet.verify_total_host_count())
     self.assertTrue(test_subnet.verify_variables())
 def test_verify_variables_network_address(self):
     test_subnet = Subnet()
     test_subnet.network_address = 0
     self.assertFalse(test_subnet.verify_network_address())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.network_address = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_network_address())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.network_address = '152.2.136.0/26'
     self.assertFalse(test_subnet.verify_network_address())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.network_address = '152.2.136.0'
     self.assertTrue(test_subnet.verify_network_address())
     self.assertTrue(test_subnet.verify_variables())
 def test_calculate_assignable_host_count(self):
     test_subnet = Subnet()
     test_subnet.total_host_count = 64
     test_subnet.calculate_assignable_host_count()
     self.assertEqual(test_subnet.assignable_host_count, 62)
 def test_verify_variables_broadcast(self):
     test_subnet = Subnet()
     test_subnet.broadcast_address = 0
     self.assertFalse(test_subnet.verify_broadcast())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.broadcast_address = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_broadcast())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.broadcast_address = '152.2.136.0/26'
     self.assertFalse(test_subnet.verify_broadcast())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.broadcast_address = '152.2.136.63'
     self.assertTrue(test_subnet.verify_broadcast())
     self.assertTrue(test_subnet.verify_variables())
 def test_calculate_netmask_from_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.calculate_netmask_from_ip_range()
     self.assertEqual(test_subnet.netmask, '255.255.255.192')
 def test_verify_variables_multiple(self):
     test_subnet = Subnet()
     test_subnet.network_address = 'THIS IS A TEST'
     test_subnet.ip_range = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.network_address = '152.2.136.0'
     test_subnet.ip_range = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.network_address = '152.2.136.0'
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     self.assertTrue(test_subnet.verify_variables())
 def test_calculate_netmask_from_cidr(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.calculate_netmask_from_cidr()
     self.assertEqual(test_subnet.netmask, '255.255.255.192')
 def test_verify_variables_assignable_host_count(self):
     test_subnet = Subnet()
     test_subnet.assignable_host_count = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_assignable_host_count())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.assignable_host_count = '123'
     self.assertFalse(test_subnet.verify_assignable_host_count())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.assignable_host_count = '62'
     self.assertTrue(test_subnet.verify_assignable_host_count())
     self.assertTrue(test_subnet.verify_variables())
 def test_calculate_total_host_count_from_netmask(self):
     test_subnet = Subnet()
     test_subnet.netmask = '255.255.255.192'
     test_subnet.calculate_total_host_count_from_netmask()
     self.assertEqual(test_subnet.total_host_count, 64)
 def test_verify_variables_netmask(self):
     test_subnet = Subnet()
     test_subnet.netmask = 0
     self.assertFalse(test_subnet.verify_netmask())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.netmask = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_netmask())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.netmask = '152.2.136.0'
     self.assertFalse(test_subnet.verify_netmask())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.netmask = '255.255.255.192'
     self.assertTrue(test_subnet.verify_netmask())
     self.assertTrue(test_subnet.verify_variables())
 def test_calculate_total_host_count_from_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.calculate_total_host_count_from_ip_range()
     self.assertEqual(test_subnet.total_host_count, 64)
Example #22
0
class NetmaskCalcGUI:
    def __init__(self):
        self.subnet = Subnet()

        self.net = Tk()
        self.net.wm_title('Netmask Calculator')

        self.netmask_from_cidr = LabelFrame(self.net,
                                            text='Netmask: CIDR Address')
        self.cidr_label = Label(self.netmask_from_cidr,
                                text='CIDR Address:',
                                width=20)
        self.cidr_entry = Entry(self.netmask_from_cidr, width=25)

        self.netmask_from_ip_range = LabelFrame(
            self.net, text='Netmask: Assignable IP Range')
        self.ip_range_label = Label(self.netmask_from_ip_range,
                                    text='Assignable IP Range:',
                                    width=20)
        self.ip_range_entry = Entry(self.netmask_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.net, text='Learning Steps')

        self.calculate = Button(self.netmask_from_cidr,
                                text='Calculate',
                                command=lambda: self.get_net_from_cidr())
        self.calculate2 = Button(self.netmask_from_ip_range,
                                 text='Calculate',
                                 command=lambda: self.get_net_from_ip_range())

        self.netmask_from_cidr.grid(row=0)
        self.netmask_from_ip_range.grid(row=1)
        self.learning_steps.grid(row=2, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.ip_range_label.grid(row=0, column=0, sticky='W')
        self.ip_range_entry.grid(row=0, column=1)
        self.calculate2.grid(row=0, column=2)

        # self.net.mainloop()

    def get_net_from_cidr(self):
        if self.subnet.netmask != '':
            self.clear_and_reset()
        else:
            self.subnet.cidr_address = self.cidr_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_netmask_from_cidr()
                steps = self.subnet.netmask_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                cidr_address = Label(self.learning_steps,
                                     text='CIDR Address: {}'.format(
                                         self.subnet.cidr_address))
                step2 = Label(self.learning_steps, text='Step 2:')
                net_bits = Label(self.learning_steps,
                                 text='Network Bits: {}'.format(
                                     steps[0]['Network Bits']))
                host_bits = Label(self.learning_steps,
                                  text='Host Bits: {}'.format(
                                      steps[0]['Host Bits']))
                step3 = Label(self.learning_steps, text='Step 3:')
                mask_binary = Label(self.learning_steps,
                                    text='Netmask Binary: {}'.format(
                                        steps[1]['Netmask Binary']))
                step4 = Label(self.learning_steps, text='Step 4:')
                netmask = Label(self.learning_steps,
                                text='Netmask: {}'.format(self.subnet.netmask))

                step1.grid(row=0, column=0, sticky='W')
                cidr_address.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                net_bits.grid(row=1, column=1, sticky='W')
                host_bits.grid(row=1, column=2, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                mask_binary.grid(row=2, column=1, columnspan=2, sticky='W')
                step4.grid(row=3, column=0, sticky='W')
                netmask.grid(row=3, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def get_net_from_ip_range(self):
        if self.subnet.netmask != '':
            self.clear_and_reset()
        else:
            self.subnet.ip_range = self.ip_range_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_netmask_from_ip_range()
                steps = self.subnet.netmask_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                ip_range = Label(self.learning_steps,
                                 text='Assignable IP Range: {}'.format(
                                     self.subnet.ip_range))
                step2 = Label(self.learning_steps, text='Step 2:')
                front = Label(self.learning_steps,
                              text='Front: {}'.format(steps[0]['Front']))
                back = Label(self.learning_steps,
                             text=' Back: {}'.format(steps[0]['Back']))
                step3 = Label(self.learning_steps, text='Step 3:')
                comparison = Label(self.learning_steps,
                                   text='Comparison: {}'.format(
                                       steps[1]['Comparison']))
                step4 = Label(self.learning_steps, text='Step 4:')
                netmask = Label(self.learning_steps,
                                text='Netmask: {}'.format(self.subnet.netmask))

                step1.grid(row=0, column=0, sticky='W')
                ip_range.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                front.grid(row=1, column=1, sticky='W')
                back.grid(row=2, column=1, sticky='W')
                step3.grid(row=3, column=0, sticky='W')
                comparison.grid(row=3, column=1, sticky='W')
                step4.grid(row=4, column=0, sticky='W')
                netmask.grid(row=4, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def clear_and_reset(self):
        self.cidr_entry.delete(0, 'end')
        self.ip_range_entry.delete(0, 'end')
        self.subnet.reset_variables()
        for child in self.learning_steps.winfo_children():
            child.destroy()

    def generate_main(self):
        self.net.mainloop()
Example #23
0
class GenSubnetCalcGUI:
    def __init__(self):
        self.subnet = Subnet()

        self.general_calculator = Tk()
        self.general_calculator.wm_title('General Subnet Calculator')

        self.cidr_label = Label(self.general_calculator, text='CIDR Address:')
        self.network_label = Label(self.general_calculator,
                                   text='Network Address:')
        self.netmask_label = Label(self.general_calculator, text='Netmask:')
        self.broadcast_label = Label(self.general_calculator,
                                     text='Broadcast Address:')
        self.ip_range_label = Label(self.general_calculator,
                                    text='Assignable IP Range:')
        self.total_host_label = Label(self.general_calculator,
                                      text='Total Host Count:')
        self.assignable_host_label = Label(self.general_calculator,
                                           text='Assignable Host Count:')

        self.cidr_entry = Entry(self.general_calculator, width=25)
        self.network_entry = Entry(self.general_calculator, width=25)
        self.netmask_entry = Entry(self.general_calculator, width=25)
        self.broadcast_entry = Entry(self.general_calculator, width=25)
        self.ip_range_entry = Entry(self.general_calculator, width=25)
        self.total_host_entry = Entry(self.general_calculator, width=25)
        self.assignable_host_entry = Entry(self.general_calculator, width=25)

        self.calculate = Button(self.general_calculator,
                                text='Calculate',
                                command=lambda: self.get_entries())

        self.cidr_label.grid(row=0, column=0, sticky='E')
        self.network_label.grid(row=1, column=0, sticky='E')
        self.netmask_label.grid(row=2, column=0, sticky='E')
        self.broadcast_label.grid(row=3, column=0, sticky='E')
        self.ip_range_label.grid(row=4, column=0, sticky='E')
        self.total_host_label.grid(row=5, column=0, sticky='E')
        self.assignable_host_label.grid(row=6, column=0, sticky='E')

        self.cidr_entry.grid(row=0, column=1)
        self.network_entry.grid(row=1, column=1)
        self.netmask_entry.grid(row=2, column=1)
        self.broadcast_entry.grid(row=3, column=1)
        self.ip_range_entry.grid(row=4, column=1)
        self.total_host_entry.grid(row=5, column=1)
        self.assignable_host_entry.grid(row=6, column=1)

        self.calculate.grid(row=7, columnspan=2)

        # self.general_calculator.mainloop()

    def clear_entries(self):
        self.cidr_entry.delete(0, 'end')
        self.network_entry.delete(0, 'end')
        self.netmask_entry.delete(0, 'end')
        self.broadcast_entry.delete(0, 'end')
        self.ip_range_entry.delete(0, 'end')
        self.total_host_entry.delete(0, 'end')
        self.assignable_host_entry.delete(0, 'end')

    def get_entries(self):
        if self.subnet.cidr_address != '':
            self.clear_entries()
            self.subnet.reset_variables()
        else:
            self.subnet.cidr_address = self.cidr_entry.get()
            self.subnet.network_address = self.network_entry.get()
            self.subnet.netmask = self.netmask_entry.get()
            self.subnet.broadcast_address = self.broadcast_entry.get()
            self.subnet.ip_range = self.ip_range_entry.get()
            self.subnet.total_host_count = self.total_host_entry.get()
            self.subnet.assignable_host_count = self.assignable_host_entry.get(
            )

            self.clear_entries()

            if self.subnet.verify_variables():
                self.subnet.general_calculation()

                self.cidr_entry.insert(0, self.subnet.cidr_address)
                self.network_entry.insert(0, self.subnet.network_address)
                self.netmask_entry.insert(0, self.subnet.netmask)
                self.broadcast_entry.insert(0, self.subnet.broadcast_address)
                self.ip_range_entry.insert(0, self.subnet.ip_range)
                self.total_host_entry.insert(0,
                                             str(self.subnet.total_host_count))
                self.assignable_host_entry.insert(
                    0, str(self.subnet.assignable_host_count))

            else:
                self.clear_entries()
                self.subnet.reset_variables()
                HelpGUI()

    def generate_main(self):
        self.general_calculator.mainloop()
 def test_verify_variables_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = 0
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = 'THIS IS A TEST'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.0/26'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.63'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.0-'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.0-152.2.136.0'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.62-152.2.136.1'
     self.assertFalse(test_subnet.verify_ip_range())
     self.assertFalse(test_subnet.verify_variables())
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     self.assertTrue(test_subnet.verify_ip_range())
     self.assertTrue(test_subnet.verify_variables())
Example #25
0
class TotalHostCalcGUI:
    def __init__(self):
        self.subnet = Subnet()

        self.total = Tk()
        self.total.wm_title('Total Host Count Calculator')

        self.count_from_cidr = LabelFrame(
            self.total, text='Total Host Count: CIDR Address')
        self.cidr_label = Label(self.count_from_cidr,
                                text='CIDR Address:',
                                width=20)
        self.cidr_entry = Entry(self.count_from_cidr, width=25)

        self.count_from_netmask = LabelFrame(self.total,
                                             text='Total Host Count: Netmask')
        self.netmask_label = Label(self.count_from_netmask,
                                   text='Netmask:',
                                   width=20)
        self.netmask_entry = Entry(self.count_from_netmask, width=25)

        self.count_from_ip_range = LabelFrame(
            self.total, text='Total Host Count: Assignable IP Range')
        self.ip_range_label = Label(self.count_from_ip_range,
                                    text='Assignable IP Range:',
                                    width=20)
        self.ip_range_entry = Entry(self.count_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.total, text='Learning Steps')

        self.calculate = Button(self.count_from_cidr,
                                text='Calculate',
                                command=lambda: self.get_count_from_cidr())
        self.calculate2 = Button(self.count_from_netmask,
                                 text='Calculate',
                                 command=lambda: self.get_count_from_netmask())
        self.calculate3 = Button(
            self.count_from_ip_range,
            text='Calculate',
            command=lambda: self.get_count_from_ip_range())

        self.count_from_cidr.grid(row=0)
        self.count_from_netmask.grid(row=1)
        self.count_from_ip_range.grid(row=2)
        self.learning_steps.grid(row=3, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.netmask_label.grid(row=0, column=0, sticky='W')
        self.netmask_entry.grid(row=0, column=1)
        self.calculate2.grid(row=0, column=2)

        self.ip_range_label.grid(row=0, column=0, sticky='W')
        self.ip_range_entry.grid(row=0, column=1)
        self.calculate3.grid(row=0, column=2)

        # self.total.mainloop()
        pass

    def get_count_from_cidr(self):
        if self.subnet.total_host_count != '':
            self.clear_and_reset()
        else:
            self.subnet.cidr_address = self.cidr_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_total_host_count_from_cidr()
                steps = self.subnet.total_host_count_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                cidr_address = Label(self.learning_steps,
                                     text='CIDR Address: {}'.format(
                                         self.subnet.cidr_address))
                step2 = Label(self.learning_steps, text='Step 2:')
                cidr = Label(self.learning_steps,
                             text='CIDR: {}'.format(steps[0]['CIDR']))
                step3 = Label(self.learning_steps, text='Step 3:')
                host = Label(self.learning_steps,
                             text='Host Bits: {}'.format(
                                 steps[1]['Host Bits']))
                step4 = Label(self.learning_steps, text='Step 4:')
                count = Label(self.learning_steps,
                              text='Total Host Count: 2{} = {}'.format(
                                  exponent(
                                      steps[1]['Host Bits'].split(' ')[-1]),
                                  self.subnet.total_host_count))

                step1.grid(row=0, column=0, sticky='W')
                cidr_address.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                cidr.grid(row=1, column=1, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                host.grid(row=2, column=1, sticky='W')
                step4.grid(row=3, column=0, sticky='W')
                count.grid(row=3, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def get_count_from_netmask(self):
        if self.subnet.total_host_count != '':
            self.clear_and_reset()
        else:
            self.subnet.netmask = self.netmask_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_total_host_count_from_netmask()
                steps = self.subnet.total_host_count_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                netmask = Label(self.learning_steps,
                                text='Netmask: {}'.format(self.subnet.netmask))
                step2 = Label(self.learning_steps, text='Step 2:')
                netmask_binary = Label(self.learning_steps,
                                       text='Netmask Binary: {}'.format(
                                           steps[0]['Netmask Binary']))
                step3 = Label(self.learning_steps, text='Step 3:')
                host = Label(self.learning_steps,
                             text='Host Bits: {}'.format(
                                 steps[1]['Host Bits']))
                step4 = Label(self.learning_steps, text='Step 4:')
                count = Label(self.learning_steps,
                              text='Total Host Count: 2{} = {}'.format(
                                  exponent(str(steps[1]['Host Bits'])),
                                  self.subnet.total_host_count))

                step1.grid(row=0, column=0, sticky='W')
                netmask.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                netmask_binary.grid(row=1, column=1, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                host.grid(row=2, column=1, sticky='W')
                step4.grid(row=3, column=0, sticky='W')
                count.grid(row=3, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def get_count_from_ip_range(self):
        if self.subnet.total_host_count != '':
            self.clear_and_reset()
        else:
            self.subnet.ip_range = self.ip_range_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_total_host_count_from_ip_range()
                steps = self.subnet.total_host_count_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                ip_range = Label(self.learning_steps,
                                 text='Assignable IP Range: {}'.format(
                                     self.subnet.ip_range))
                step2 = Label(self.learning_steps, text='Step 2:')
                front = Label(self.learning_steps,
                              text='Front: {}'.format(steps[0]['Front']))
                back = Label(self.learning_steps,
                             text=' Back: {}'.format(steps[0]['Back']))
                step3 = Label(self.learning_steps, text='Step 3:')
                comparison = Label(self.learning_steps,
                                   text='Comparison: {}'.format(
                                       steps[1]['Comparison']))
                step4 = Label(self.learning_steps, text='Step 4:')
                host = Label(self.learning_steps,
                             text='Host Bits: {}'.format(
                                 steps[2]['Host Bits']))
                step5 = Label(self.learning_steps, text='Step 5:')
                count = Label(self.learning_steps,
                              text='Total Host Count: 2{} = {}'.format(
                                  exponent(str(steps[2]['Host Bits'])),
                                  self.subnet.total_host_count))

                step1.grid(row=0, column=0, sticky='W')
                ip_range.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                front.grid(row=1, column=1, sticky='W')
                back.grid(row=2, column=1, sticky='W')
                step3.grid(row=3, column=0, sticky='W')
                comparison.grid(row=3, column=1, sticky='W')
                step4.grid(row=4, column=0, sticky='W')
                host.grid(row=4, column=1, sticky='W')
                step5.grid(row=5, column=0, sticky='W')
                count.grid(row=5, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def clear_and_reset(self):
        self.cidr_entry.delete(0, 'end')
        self.netmask_entry.delete(0, 'end')
        self.ip_range_entry.delete(0, 'end')
        self.subnet.reset_variables()
        for child in self.learning_steps.winfo_children():
            child.destroy()

    def generate_main(self):
        self.total.mainloop()
 def test_calculate_network_address_from_cidr(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.calculate_network_address_from_cidr()
     self.assertEqual(test_subnet.network_address, '152.2.136.0')
Example #27
0
class IPRangeCalcGUI:
    def __init__(self):
        self.subnet = Subnet()

        self.range = Tk()
        self.range.wm_title('Assignable IP Range Calculator')

        self.ip_range_from_cidr = LabelFrame(self.range, text='Assignable IP Range: CIDR Address')
        self.cidr_label = Label(self.ip_range_from_cidr, text='CIDR Address:', width=25)
        self.cidr_entry = Entry(self.ip_range_from_cidr, width=25)

        self.ip_range_from_network_broadcast = LabelFrame(self.range, text='Assignable IP Range: Network '
                                                                           'Address, Broadcast Address')
        self.network = Label(self.ip_range_from_network_broadcast, text='Network Address:', width=25)
        self.broadcast = Label(self.ip_range_from_network_broadcast, text='Broadcast Address:', width=25)
        self.network_entry = Entry(self.ip_range_from_network_broadcast, width=25)
        self.broadcast_entry = Entry(self.ip_range_from_network_broadcast, width=25)

        self.learning_steps = LabelFrame(self.range, text='Learning Steps')

        self.calculate = Button(self.ip_range_from_cidr, text='Calculate',
                                command=lambda: self.get_ip_range_from_cidr())
        self.calculate2 = Button(self.ip_range_from_network_broadcast, text='Calculate',
                                 command=lambda: self.get_ip_range_from_network_broadcast())

        self.ip_range_from_cidr.grid(row=0)
        self.ip_range_from_network_broadcast.grid(row=1)
        self.learning_steps.grid(row=2, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.network.grid(row=0, column=0, sticky='W')
        self.broadcast.grid(row=0, column=1, sticky='W')
        self.network_entry.grid(row=1, column=0)
        self.broadcast_entry.grid(row=1, column=1)
        self.calculate2.grid(row=1, column=2)

        # self.broadcast.mainloop()

    def get_ip_range_from_cidr(self):
        if self.subnet.ip_range != '':
            self.clear_and_reset()
        else:
            self.subnet.cidr_address = self.cidr_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_ip_range_from_cidr()
                steps = self.subnet.ip_range_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                cidr_address = Label(self.learning_steps, text='CIDR Address: {}'.format(self.subnet.cidr_address))
                step2 = Label(self.learning_steps, text='Step 2:')
                front = Label(self.learning_steps, text='Front: {}'.format(steps[0]['Front']))
                step3 = Label(self.learning_steps, text='Step 3:')
                cidr = Label(self.learning_steps, text='CIDR: {}'.format(steps[1]['CIDR']))
                host = Label(self.learning_steps, text='Host Bits: 32 - {} = {}'.format(steps[1]['CIDR'],
                                                                                        (32 - int(steps[1]['CIDR']))))
                step4 = Label(self.learning_steps, text='Step 4:')
                net_binary = Label(self.learning_steps, text='Network Binary: {}'.format(steps[1]['Network Binary']))
                step5 = Label(self.learning_steps, text='Step 5:')
                back_binary = Label(self.learning_steps,
                                    text='Back Binary (Broadcast - 1): {}'.format(steps[2]['Back Binary']))
                step6 = Label(self.learning_steps, text='Step 6:')
                ip_range = Label(self.learning_steps, text='Assignable IP Range: {}'.format(self.subnet.ip_range))

                step1.grid(row=0, column=0, sticky='W')
                cidr_address.grid(row=0, column=1, columnspan=2, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                front.grid(row=1, column=1, columnspan=2, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                cidr.grid(row=2, column=1, sticky='W')
                host.grid(row=2, column=2, sticky='W')
                step4.grid(row=3, column=0, sticky='W')
                net_binary.grid(row=3, column=1, columnspan=2, sticky='W')
                step5.grid(row=4, column=0, sticky='W')
                back_binary.grid(row=4, column=1, columnspan=2, sticky='W')
                step6.grid(row=5, column=0, sticky='W')
                ip_range.grid(row=5, column=1, columnspan=2, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def get_ip_range_from_network_broadcast(self):
        if self.subnet.ip_range != '':
            self.clear_and_reset()
        else:
            self.subnet.network_address = self.network_entry.get()
            self.subnet.broadcast_address = self.broadcast_entry.get()

            if self.subnet.network_address != '' and self.subnet.broadcast_address != '' \
                    and self.subnet.verify_variables() \
                    and (ipaddress.IPv4Address(self.subnet.network_address) + 2) \
                            < ipaddress.IPv4Address(self.subnet.broadcast_address):
                self.subnet.calculate_ip_range_from_network_broadcast()
                steps = self.subnet.ip_range_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                network = Label(self.learning_steps, text='Network Address: {}'.format(self.subnet.network_address))
                broadcast = Label(self.learning_steps,
                                  text='Broadcast Address: {}'.format(self.subnet.broadcast_address))
                step2 = Label(self.learning_steps, text='Step 2:')
                front = Label(self.learning_steps, text='Front: {}'.format(steps[0]['Front']))
                step3 = Label(self.learning_steps, text='Step 3:')
                back = Label(self.learning_steps, text='Back: {}'.format(steps[1]['Back']))
                step4 = Label(self.learning_steps, text='Step 4:')
                ip_range = Label(self.learning_steps, text='Assignable IP Range: {}'.format(self.subnet.ip_range))

                step1.grid(row=0, column=0, sticky='W')
                network.grid(row=0, column=1, sticky='W')
                broadcast.grid(row=0, column=2, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                front.grid(row=1, column=1, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                back.grid(row=2, column=1, sticky='W')
                step4.grid(row=3, column=0, sticky='W')
                ip_range.grid(row=3, column=1, columnspan=2, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def clear_and_reset(self):
        self.cidr_entry.delete(0, 'end')
        self.network_entry.delete(0, 'end')
        self.broadcast_entry.delete(0, 'end')
        self.subnet.reset_variables()
        for child in self.learning_steps.winfo_children():
            child.destroy()

    def generate_main(self):
        self.range.mainloop()
 def test_calculate_network_address_from_ip_range(self):
     test_subnet = Subnet()
     test_subnet.ip_range = '152.2.136.1-152.2.136.62'
     test_subnet.calculate_network_address_from_ip_range()
     self.assertEqual(test_subnet.network_address, '152.2.136.0')
Example #29
0
class NetCalcGUI:
    def __init__(self):
        self.subnet = Subnet()

        self.net = Tk()
        self.net.wm_title('Network Address Calculator')

        self.net_from_cidr = LabelFrame(self.net,
                                        text='Network Address: CIDR Address')
        self.cidr_label = Label(self.net_from_cidr,
                                text='CIDR Address:',
                                width=20)
        self.cidr_entry = Entry(self.net_from_cidr, width=25)

        self.net_from_ip_range = LabelFrame(
            self.net, text='Network Address: Assignable IP Range')
        self.ip_range_label = Label(self.net_from_ip_range,
                                    text='Assignable IP Range:',
                                    width=20)
        self.ip_range_entry = Entry(self.net_from_ip_range, width=25)

        self.learning_steps = LabelFrame(self.net, text='Learning Steps')

        self.calculate = Button(self.net_from_cidr,
                                text='Calculate',
                                command=lambda: self.get_net_from_cidr())
        self.calculate2 = Button(self.net_from_ip_range,
                                 text='Calculate',
                                 command=lambda: self.get_net_from_ip_range())

        self.net_from_cidr.grid(row=0)
        self.net_from_ip_range.grid(row=1)
        self.learning_steps.grid(row=2, sticky='W')

        self.cidr_label.grid(row=0, column=0, sticky='W')
        self.cidr_entry.grid(row=0, column=1)
        self.calculate.grid(row=0, column=2)

        self.ip_range_label.grid(row=0, column=0, sticky='W')
        self.ip_range_entry.grid(row=0, column=1)
        self.calculate2.grid(row=0, column=2)

        # self.net.mainloop()

    def get_net_from_cidr(self):
        if self.subnet.network_address != '':
            self.clear_and_reset()
        else:
            self.subnet.cidr_address = self.cidr_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_network_address_from_cidr()

                step1 = Label(self.learning_steps, text='Step 1:')
                cidr_address = Label(self.learning_steps,
                                     text='CIDR Address: {}'.format(
                                         self.subnet.cidr_address))
                step2 = Label(self.learning_steps, text='Step 2:')
                network = Label(self.learning_steps,
                                text='Network Address: {}'.format(
                                    self.subnet.network_address))

                step1.grid(row=0, column=0, sticky='W')
                cidr_address.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                network.grid(row=1, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def get_net_from_ip_range(self):
        if self.subnet.network_address != '':
            self.clear_and_reset()
        else:
            self.subnet.ip_range = self.ip_range_entry.get()

            if self.subnet.verify_variables():
                self.subnet.calculate_network_address_from_ip_range()
                steps = self.subnet.network_address_steps

                step1 = Label(self.learning_steps, text='Step 1:')
                ip_range = Label(self.learning_steps,
                                 text='Assignable IP Range: {}'.format(
                                     self.subnet.ip_range))
                step2 = Label(self.learning_steps, text='Step 2:')
                front = Label(self.learning_steps,
                              text='(Front - 1): {}'.format(
                                  steps[0]['Front - 1']))
                step3 = Label(self.learning_steps, text='Step 3:')
                network = Label(self.learning_steps,
                                text='Network Address: {}'.format(
                                    self.subnet.network_address))

                step1.grid(row=0, column=0, sticky='W')
                ip_range.grid(row=0, column=1, sticky='W')
                step2.grid(row=1, column=0, sticky='W')
                front.grid(row=1, column=1, sticky='W')
                step3.grid(row=2, column=0, sticky='W')
                network.grid(row=2, column=1, sticky='W')
            else:
                self.clear_and_reset()
                HelpGUI()

    def clear_and_reset(self):
        self.cidr_entry.delete(0, 'end')
        self.ip_range_entry.delete(0, 'end')
        self.subnet.reset_variables()
        for child in self.learning_steps.winfo_children():
            child.destroy()

    def generate_main(self):
        self.net.mainloop()
 def test_calculate_broadcast_address_from_cidr(self):
     test_subnet = Subnet()
     test_subnet.cidr_address = '152.2.136.0/26'
     test_subnet.calculate_broadcast_address_from_cidr()
     self.assertEqual(test_subnet.broadcast_address, '152.2.136.63')