Node JS return hostname

According to the node.js documentation for the “os” module you need to load the “os” module, which has a hostname() function: var os = require(“os”); var hostname = os.hostname(); However, that only is the hostname – without the domain name (the FQDN). There is no easy way to get the FQDN. You could use the … Read more

How to reach docker containers by name instead of IP address?

Docker 1.10 has a built in DNS. If your containers are connected to the same user defined network (create a network docker network create my-network and run your container with –net my-network) they can reference each other using the container name. (Docs). Cool! One caveat if you are using Docker compose you know that it … Read more

How to get hostname from IP (Linux)?

To find a hostname in your local network by IP address you can use nmblookup from the samba suite: nmblookup -A <ip> To find a hostname on the internet you could use the host program: host <ip> Or you can install nbtscan by running: sudo apt-get install nbtscan And use: nbtscan <ip> *Adapted from https://askubuntu.com/questions/205063/command-to-get-the-hostname-of-remote-server-using-ip-address/205067#205067 … Read more

Get hostname of current request in node.js Express

You can use the os Module: var os = require(“os”); os.hostname(); See http://nodejs.org/docs/latest/api/os.html#os_os_hostname Caveats: if you can work with the IP address — Machines may have several Network Cards and unless you specify it node will listen on all of them, so you don’t know on which NIC the request came in, before it comes … Read more

Recommended way to get hostname in Java

Strictly speaking – you have no choice but calling either hostname(1) or – on Unix gethostname(2). This is the name of your computer. Any attempt to determine the hostname by an IP address like this InetAddress.getLocalHost().getHostName() is bound to fail in some circumstances: The IP address might not resolve into any name. Bad DNS setup, … Read more

How to extract the hostname portion of a URL in JavaScript

suppose that you have a page with this address: http://sub.domain.com/virtualPath/page.htm. use the following in page code to achieve those results: window.location.host : you’ll get sub.domain.com:8080 or sub.domain.com:80 window.location.hostname : you’ll get sub.domain.com window.location.protocol : you’ll get http: window.location.port : you’ll get 8080 or 80 window.location.pathname : you’ll get /virtualPath window.location.origin : you’ll get http://sub.domain.com ***** … Read more