If Powershell Core
on Linux, using dotnet
, can return the FQDN
, then how does mono
, also using dotnet
, get the same result?
Here's powershell
finding the local system FQDN
:
thufir@dur:~/powershell$
thufir@dur:~/powershell$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/thufir/powershell>
PS /home/thufir/powershell> [System.Net.Dns]::GetHostByName((hostname)).HostName
dur.bounceme.net
PS /home/thufir/powershell>
and mono
:
thufir@dur:~$
thufir@dur:~$ mono Projects/console/console/bin/Debug/console.exe
Hello Mono World
dur
dur
localhost
localhost
localhost
dur
done
thufir@dur:~$
code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Globalization;
using System.Text;
namespace console
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello Mono World");
String name;
name = Environment.MachineName;
Console.WriteLine(name);
name = System.Net.Dns.GetHostName();
Console.WriteLine(name);
name = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
Console.WriteLine(name);
name =System.Net.Dns.GetHostEntry("localhost").HostName;
Console.WriteLine(name);
name = Dns.GetHostEntry("LocalHost").HostName;
Console.WriteLine(name);
// var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
// name = string.Format("{0}.{1}", ipProperties.HostName, ipProperties.DomainName);
// Console.WriteLine(name);
name = Dns.GetHostEntry("LocalHost").HostName;
Console.WriteLine(name);
name = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
Console.WriteLine(name);
Console.WriteLine("done");
}
}
}
thanks to jjw for pointing me in the right direction.
This is tantalizingly close, because dur
, which is how the prompt is shown, is listed. Just not the whole name. Also:
thufir@dur:~$
thufir@dur:~$ hostname
dur
thufir@dur:~$
thufir@dur:~$ hostname --fqdn
dur.bounceme.net
thufir@dur:~$
thufir@dur:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 dur.bounceme.net dur
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
thufir@dur:~$
thufir@dur:~$ cat /etc/hostname
dur
thufir@dur:~$
Looking for the whole enchilada here, not just the prepend of dur
but dur.bounceme.net
if possible. Because Powershell Core
can find the FQDN
shouldn't mono
be able to do the same?