InterviewSolution
| 1. |
What are IP address versions? How does Python manage IP addresses? |
|
Answer» IP address is a string of decimal (or hexadecimal) numbers that forms a unique identity of each device connected to a computer network that uses INTERNET Protocol for data communication. The IP address has two purposes: identifying host and location addressing. To start with IP addressing scheme uses 32 bits comprising of four octets each of 8 bits having a value equivalent to a decimal number between 0-255. The octets are separated by dot (.). For example 111.91.41.196 This addressing scheme is called Ipv4 scheme. As a result of rapid increase in the number of devices directly connected to the internet, this scheme is being GRADUALLY replaced by Ipv6 version. An IPv6 address uses hexadecimal digits to represent a string of unique 128 bit number. Each position in an IPv6 address represents four bits with a value from 0 to f. The 128 bits are divided into 8 groupings of 16 bits each separated by colons. Example: 2001:db8:abcd:100::1/64 The IPv6 address always uses CIDR notation to determine how many of the leading bits are used for network identification and rest for host/interface identification. Python's ipaddress module provides the capability to create, manipulate and operate on IPv4 and IPv6 addresses and networks. Following factory FUNCTIONS help to CONVENIENTLY create IP addresses, networks and interfaces: ip_address(): This function returns an IPv4Address or IPv6Address object depending on the IP address passed as argument. >>> import ipaddress >>> ipaddress.ip_address('192.168.0.1') IPv4Address('192.168.0.1') >>> ipaddress.ip_address('2001:ab7::') IPv6Address('2001:ab7::')ip_network(): This function returns an IPv4Network or IPv6Network object depending on the IP address passed as argument. >>> ipaddress.ip_network('192.168.100.0/24') IPv4Network('192.168.100.0/24') >>> ipaddress.ip_network('2001:db8:abcd:100::/64') IPv6Network('2001:db8:abcd:100::/64')ip_interface(): This function returns IPv4Interface or IPv6Interface object . >>> ipaddress.ip_interface('192.168.100.10/24') IPv4Interface('192.168.100.10/24') >>> ipaddress.ip_interface('2001:db8:abcd:100::1/64') IPv6Interface('2001:db8:abcd:100::1/64') |
|