Is it possible to detect the hostname used in java (even through a cname)?
I am looking for something similar to this: http://api.drupal.org/api/function/conf_path/6
In that code, drupal checks to see what domain name is accessing it in order to load the correct configuration (multi-site). If the domain doesn't match any configurations, it just goes to the default configuration.
Have a look at InetAddress.getLocalHost(), followed by calling getHostName() on the returned value, which does exactly this.
Be aware that not all machines will be able to resolve a network interface which can be used for the local hostname, and that multi-homed machines run into some additional complications too. Thus if you're developing software that will need to work in a variety of situations, consider the edge cases properly as well as the happy path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With