According to the documentation, function os.Hostname() returns the system host name reported by kernel. So, if your computer is named computer1, os.Hostname() returns computer1. If your computer is named computer1.my.office, os.Hostname() returns computer1.my.office. On Windows, is the same. If you want the domain name (as referred to the Active Directory domain) you have four ways:
Parse the result of this command: wmic computersystem get domain
Parse the result of this command: systeminfo | findstr /B /C:"Domain"
Assume the existence of the environment variable USERDNSDOMAIN and evaluate his value (note that: the value of this variable is referred at the domain which user is stored)
Check if one of the ip's assigned to the workstation can be resolved via DNS (for this point, you can view this: https://github.com/Showmax/go-fqdn)
You can perform some gymnastics using the net lib as demonstrated here.
By default there is no short way.
os.Hostname() doesn't provide the Fully Qualified Domain Name by default.
According to the documentation, function
os.Hostname()
returns the system host name reported by kernel. So, if your computer is namedcomputer1
,os.Hostname()
returnscomputer1
. If your computer is namedcomputer1.my.office
,os.Hostname()
returnscomputer1.my.office
. On Windows, is the same. If you want the domain name (as referred to the Active Directory domain) you have four ways:wmic computersystem get domain
systeminfo | findstr /B /C:"Domain"
USERDNSDOMAIN
and evaluate his value (note that: the value of this variable is referred at the domain which user is stored)