How can I match user input string with everything localhost means?

I need to indicate if the user enters the name of the local machine in the text box. It turned out to be more complicated than I originally thought.

string userInput = inputTextbox.Text.ToLower();
string machineName = Environment.MachineName.ToLower();

bool isLocal = userInput.Equals(machineName ) || // This is what we started with...
             userInput.Equals(".") ||             // Then we added this...
             userInput.Equals("localhost");       // And then we added this...

As you can see, it has become quite dirty and overwhelming. For example, the address 127.0.0.1 was not included. Our testing department continues to write bugs every time they find a new name for the house. We need to break this mistake once and for all.

Is there an easier way to do this?

+4
source share
2 answers

There are many definitions for this machine.

  • All IP addresses in all adapters (wireless, vpn and dhcp are here to interfere further)
  • 127.x.y.x ( @, )
  • IP- hosts
  • dns
  • dns, ( DNS http hostname)
  • . char ( , SQL-)
  • , IP-, . , : ping 2130706433

, . 80% . %20 - "" .

BTW, , , . QA.

0

-

List<String> localNames = new List<string>{Environment.MachineName.ToLower(), ".", "localhost"};

bool isLocal = localNames.Any(s=>s.Equals(userInput));

, . , . IP- .

- .

-1

All Articles