Skip to content

Instantly share code, notes, and snippets.

@zhovner zhovner/

Last active Dec 11, 2015
What would you like to do?
Python network
# Validate IP address
import socket
def valid_ip(ipaddress):
return True
return False
# Validate domain name
def valid_domain(domainstring):
# Lookahead makes sure that it has a minimum of 4 ( and a maximum of 255 characters
# One or more labels (separated by periods) of length between 1 to 63, starting and ending with alphanumeric characters, and containing alphanumeric chars and hyphens in the middle.
# Followed by a top level domain name (whose max length is 5 for museum)
dpattern = '^(?=.{4,255}$)([a-zA-Z0-9]{,61}[a-zA-Z0-9]\.)+[a-zA-Z]{2,5}$'
if re.match(dpattern, domainstring):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.