Validate a hostname string

import re def is_valid_hostname(hostname): if len(hostname) > 255: return False if hostname[-1] == “.”: hostname = hostname[:-1] # strip exactly one dot from the right, if present allowed = re.compile(“(?!-)[A-Z\d-]{1,63}(?<!-)$”, re.IGNORECASE) return all(allowed.match(x) for x in hostname.split(“.”)) ensures that each segment contains at least one character and a maximum of 63 characters consists only of … Read more

Fully qualified domain name validation

(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$) regex is always going to be at best an approximation for things like this, and rules change over time. the above regex was written with the following in mind and is specific to hostnames– Hostnames are composed of a series of labels concatenated with dots. Each label is 1 to 63 characters long, and … Read more

How to find FQDN of local machine in C#/.NET ?

NOTE: This solution only works when targeting the .NET 2.0 (and newer) frameworks. using System; using System.Net; using System.Net.NetworkInformation; //… public static string GetFQDN() { string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; string hostName = Dns.GetHostName(); domainName = “.” + domainName; if(!hostName.EndsWith(domainName)) // if hostname does not already include domain name { hostName += domainName; // add the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)