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

python: check if a hostname is resolved

You can use socket.gethostbyname() for this: >>> import socket >>> socket.gethostbyname(‘google.com’) ‘74.125.224.198’ >>> socket.gethostbyname(‘foo’) # no host ‘foo’ exists on the network Traceback (most recent call last): File “<stdin>”, line 1, in <module> socket.gaierror: [Errno 8] nodename nor servname provided, or not known Your function might look like this: def hostname_resolves(hostname): try: socket.gethostbyname(hostname) return 1 … Read more

Java: Common way to validate and convert “host:port” to InetSocketAddress?

I myself propose one possible workaround solution. Convert a string into URI (this would validate it automatically) and then query the URI’s host and port components. Sadly, an URI with a host component MUST have a scheme. This is why this solution is “not perfect”. String string = … // some string which has to … Read more

Host Name Vs Canonical Host Name

There are a few difference between the two: getCanonicalHostName() will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereas getHostName() might just return foo. getCanonicalHostName() will always do a reverse DNS lookup, whereas getHostName() would return the stored hostname if you supplied one in the InetAddress constructor. I suspect you will be wanting … Read more

Java SSL: how to disable hostname verification

It should be possible to create custom java agent that overrides default HostnameVerifier: import javax.net.ssl.*; import java.lang.instrument.Instrumentation; public class LenientHostnameVerifierAgent { public static void premain(String args, Instrumentation inst) { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String s, SSLSession sslSession) { return true; } }); } } Then just add -javaagent:LenientHostnameVerifierAgent.jar to program’s java startup arguments.

Running IIS Express with admin privileges

For Visual Studio 2015 and 2012 this solution will work. Go to Solution Explorer in Visual Studio, right click the web project and select “Unload Project” Next on the same project, right click and select ‘Edit Project File‘ Find the <DevelopmentServerPort>0</DevelopmentServerPort><IISUrl>http://localhost:56058/</IISUrl> xml tags and and remove them. Reload the project and run. Images to follow:

tech