## Task

Generate a sorted list of all possible IP addresses in a network.

For a subnet that is not a valid IPv4 network return `None`.

## Examples
```
ipsubnet2list("192.168.1.0/31") == ["192.168.1.0", "192.168.1.1"]
ipsubnet2list("213.256.46.160/28") == None
```

Difficulty: EASY
Tags: Fundamentals

Starter code:
def ipsubnet2list(subnet):
	

Solutions:
import ipaddress as ip

def ipsubnet2list(subnet):
	try:
		return list(map(str, ip.ip_network(subnet).hosts()))
	except:
		pass


def ip_to_int(ip):
	return sum((int(i[0]) << i[1] * 8 for i in zip(ip.split('.'), range(3, -1, -1))))

def int_to_ip(num):
	return '.'.join((str(num >> i * 8 & 255) for i in range(3, -1, -1)))

def ipsubnet2list(subnet):
	(net, prelen) = subnet.split('/')
	(num, mask) = (ip_to_int(net), 1 << 32 - int(prelen))
	if net != int_to_ip(num):
		return None
	if mask == 2:
		return [int_to_ip(num), int_to_ip(num + 1)]
	return [int_to_ip(num ^ i) for i in range(1, mask - 1)]


from ipaddress import ip_network
from typing import List, Union

def ipsubnet2list(subnet: str) -> Union[List[str], None]:
	try:
		return list(map(str, ip_network(subnet).hosts()))
	except ValueError:
		return


def cidr_to_bits(subnet):
	subnet_int = int(subnet[-2:])
	mask_in_bits = [(1, 0)[i > subnet_int] for i in range(1, 33)]
	return mask_in_bits

def ip_bits(subnet):
	ip_bits_str = list([format(int(x), '#010b')[2:] for x in subnet[:-3].split('.')])
	ip_bits_int = [int(i) for x in ip_bits_str for i in x]
	return ip_bits_int

def f_addr_bits(x):
	return [i & j for (i, j) in zip(ip_bits(x), cidr_to_bits(x))]

def l_addr_bits(x):
	not_on_mask = [(0, 1)[i == 0] for i in cidr_to_bits(x)]
	return [i | j for (i, j) in zip(f_addr_bits(x), not_on_mask)]

def address_to_int(bits_lst):
	return [int(''.join((str(bits_lst[y + i]) for i in range(8))), 2) for y in range(0, 32, 8)]

def list_of_addresses(x):
	first_address = address_to_int(f_addr_bits(x))
	last_address = address_to_int(l_addr_bits(x))
	octets_ranges = [[i for i in range(i, j + 1)] if j - i != 0 else [i] for (i, j) in zip(first_address, last_address)]
	addresses = []
	for first_oct in octets_ranges[0]:
		for second in octets_ranges[1]:
			for third in octets_ranges[2]:
				for fourth in octets_ranges[3]:
					addresses.append(f'{first_oct}.{second}.{third}.{fourth}')
	return addresses

def ipsubnet2list(subnet):
	result = list_of_addresses(subnet)
	if subnet[:-3] in result:
		if len(result) == 2:
			return result
		return result[1:-1]
	else:
		return None


from ipaddress import ip_network

def ipsubnet2list(subnet):
	try:
		return [ip.compressed for ip in ip_network(subnet).hosts()]
	except ValueError:
		return


from ipaddress import IPv4Network, AddressValueError

def ipsubnet2list(subnet):
	try:
		return list(map(str, IPv4Network(subnet).hosts()))
	except AddressValueError:
		return None


from ipaddress import IPv4Network, AddressValueError

def ipsubnet2list(subnet):
	try:
		ip_list = [str(ip) for ip in IPv4Network(subnet)]
		return ip_list[1:-1] if len(ip_list) > 2 else ip_list
	except AddressValueError:
		return None


def ipsubnet2list(subnet):
	import ipaddress
	ls = []
	try:
		for i in ipaddress.IPv4Network(subnet):
			ls.append(str(i))
	except:
		return None
	return ls[1:-1] if len(ls) > 2 else ls


def ipsubnet2list(subnet):
	(netaddr, prefix) = subnet.split('/')
	if not all([0 <= int(x) < 256 for x in netaddr.split('.')]):
		return None
	netaddrbyte = 0
	for x in netaddr.split('.'):
		netaddrbyte = netaddrbyte * 256 + int(x)
	r = []
	for i in range(2 ** (32 - int(prefix))):
		addr = netaddrbyte + i
		a = []
		for _ in range(4):
			a.append(addr % 256)
			addr //= 256
		r.append('.'.join(map(str, a[::-1])))
	if int(prefix) < 31:
		r = r[1:-1]
	return r


def ipsubnet2list(s):
	try:
		return [str(x) for x in list(__import__('ipaddress').ip_network(s).hosts())]
	except ValueError:
		return None