Host name resolution without changing hosts file

I am trying to figure out how to make a way to determine the host name by a specific IP address without changing the DNS or host name.

Using C #, I make a request from the client to the server, but I have to use the host name in the request so that the certificates authenticate the request correctly. However, my program is designed to run without administrator rights, so I can not change the host file. I have the correct IP and host name, is there any other way to get the computer to resolve the IP host name?

+5
source share
5 answers

, - , . . , .

+2

HTTP-, ; IP- URL- HTTP-.

HttpWebRequest.Host

: , . , hosts ( ). , , 127.0.0.1 ( ). -, -. , .

+1

: .

( , SO).

0
   public bool ModifyHostsFile(string sEntryIPAddr, string sEntryURL)
    {
        try
        {
            using (StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts")))
            {
                w.WriteLine(sEntryIPAddr+" "+ sEntryURL);
                return true;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            return false;
        }
    }
-1

:

1. "" Windows, "" "".

Step 2. Select "Run as administrator", and then, inside the notebook, find the folder (/ windows / system32 / drivers / etc) containing the hosts file.

-3
source

All Articles