Validating string for FDQN

Nobody nobody at nowhere.com
Tue Jun 7 01:23:30 EDT 2011


On Mon, 06 Jun 2011 17:40:29 -0700, Eric wrote:

> Is there a library or regex that can determine if a string is a fqdn
> (fully qualified domain name)? I'm writing a script that needs to add
> a defined domain to the end of a hostname if it isn't already a fqdn
> and doesn't contain the defined domain.

Try socket.getfqdn() or socket.gethostbyname_ex().

With one exception[1], you can't reliably do it just by examining the
string; you have to ask the resolver.

[1] If a hostname ends with a dot, it's fully qualified.




More information about the Python-list mailing list