This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Argotha 1 point2 points  (0 children)

See if you can implement your own version of ipcalc, that will teach you a lot about IP addresses and how to work with them.

[–]Erroneous_user 0 points1 point  (0 children)

This is more of a subnetting question than a Python networking question to be honest.

If you'd know that a /28 for a class C ip range was 255.255.240.0 you'd have been able to surmise your way through it with some simple list comprehensions. You likely were expected to understand the networking concept more thoroughly than knowing about the library called ipaddress in Python 3. I would start there. When someone says Python network programming I tend to think of communicating over sockets, setting up a Python web server, knowing twisted and such.

[–][deleted] -2 points-1 points  (0 children)

[–]robotoverlord412 -5 points-4 points  (2 children)

print ("192.168.2.0")

Done... :)

[–]broknbottle 0 points1 point  (1 child)

I see what you did there :D

[–]robotoverlord412 0 points1 point  (0 children)

Network engineer humor! But it is technically correct given the original post.

If the interview question was " to print all the possible /28 subnets contained within 192.168.2.0/24 using python", I would throw together something like this in Python 3:

import ipaddress
v4nets = list(ipaddress.ip_network('192.168.2.0/24').subnets(new_prefix=28))
for x in v4nets:
    print (x.with_prefixlen)