-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (17 loc) · 1.44 KB
/
index.js
File metadata and controls
21 lines (17 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const os = require('os')
let hostname = os.hostname()
if (process.platform === 'win32') {
// Get the primary DNS suffix (domain name) for the computer under Windows 10.
const domain = require('child_process').execSync('powershell -Command [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName').toString().replace(/\r\n/, '')
if (domain === '') {
// The primary DNS suffix has not been set. We will fall back to returning the result from os.hostname()
// but let’s also warn the person that this is probably not what they expect and tell them how they can
// fix it by setting the primary DNS suffix.
console.log('\n[Windows hostname warning] Your primary DNS suffix is not set so we cannot calculate your hostname (full computer name). We are falling back to your computer name as retuned by os.hostname(). The app you’re running will most likely not work properly. To set your primary DNS suffix on Windows 10, go to Control Panel → System And Security → System → Change Settings link (next to Computer name) → [Change…] Button → [More…] Button → enter your domain name under Primary DNS suffix of this computer.\n')
} else {
// Calculate the full computer name under Windows 10 and return it.
// This is what we take as being equivalent to the hostname on Linux and macOS.
hostname = `${hostname}.${domain}`
}
}
module.exports = hostname