December 2018
Intermediate to advanced
226 pages
4h 57m
English
In the expanding landscape of networking, a network engineer is faced with the additional task of validations of any IPv6 address. Let's see a sample code to validate the IPv4 and IPv6 IP addresses using the socket library:
import socketdef validateipv4ip(address): try: socket.inet_aton(address) print ("Correct IPv4 IP "+address) except socket.error: print ("wrong IPv4 IP "+address)def validateipv6ip(address): ### for IPv6 IP address validation try: socket.inet_pton(socket.AF_INET6,address) print ("Correct IPv6 IP "+address) except socket.error: print ("wrong IPv6 IP "+address)#correct IPs:validateipv4ip("8.8.8.8")validateipv6ip("2001:0db8:85a3:0000:0000:8a2e:0370:7334")#Wrong IPs:validateipv4ip("192.178.263.22") ...Read now
Unlock full access