Esempio n. 1
0
    def test_calculate_cidr(self):

        start_addr = '74.125.0.0'
        end_addr = '74.125.255.255'
        self.assertIsInstance(calculate_cidr(start_addr, end_addr), list)

        start_addr_6 = '2001:240::'
        end_addr_6 = '2001:240:ffff:ffff:ffff:ffff:ffff:ffff'
        self.assertIsInstance(calculate_cidr(start_addr_6, end_addr_6), list)
Esempio n. 2
0
async def cid(ctx, ip1: str, ip2: str):
    await ctx.message.delete()
    data = (calculate_cidr(ip1, ip2))
    channel = bot.get_channel(801841617254088705)
    await channel.send(f'```yaml\n CIDR range(s) for {ip1} & {ip2}\n```'
                       f'```yaml\n {data}```')

    @cid.error
    async def cid_error(ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            await ctx.send('Please specify a beginning and ending IP address.')
Esempio n. 3
0
    action='store_true',
    help='If set, colorizes the output using ANSI. Should work in most '
    'platform consoles.')

# Get the args
script_args = parser.parse_args()

if script_args.ipv4_lstrip_zeros:

    print((ipv4_lstrip_zeros(address=script_args.ipv4_lstrip_zeros[0])))

elif script_args.calculate_cidr:

    try:

        result = calculate_cidr(start_address=script_args.calculate_cidr[0],
                                end_address=script_args.calculate_cidr[1])

        print(('{0}Found {1} CIDR blocks for ({2}, {3}){4}:\n{5}'.format(
            ANSI['green'] if script_args.colorize else '', len(result),
            script_args.calculate_cidr[0], script_args.calculate_cidr[1],
            ANSI['end'] if script_args.colorize else '', '\n'.join(result))))

    except Exception as e:

        print(('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e))))

elif script_args.get_countries:

    try:

        result = get_countries()
Esempio n. 4
0
         'platform consoles.'
)

# Get the args
script_args = parser.parse_args()

if script_args.ipv4_lstrip_zeros:

    print(ipv4_lstrip_zeros(address=script_args.ipv4_lstrip_zeros[0]))

elif script_args.calculate_cidr:

    try:

        result = calculate_cidr(
            start_address=script_args.calculate_cidr[0],
            end_address=script_args.calculate_cidr[1]
        )

        print('{0}Found {1} CIDR blocks for ({2}, {3}){4}:\n{5}'.format(
            ANSI['green'] if script_args.colorize else '',
            len(result),
            script_args.calculate_cidr[0],
            script_args.calculate_cidr[1],
            ANSI['end'] if script_args.colorize else '',
            '\n'.join(result)
        ))

    except Exception as e:

        print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))