Question : In Windows, is there a way to map hostnames to IP addresses programatically?

I am attempting to use plink to establish an SSH session. I would like to refer to host machines using a hostname rather than an ip address such as 127.0.0.2, etc. If I updated the ..\system32\drivers\etc\hosts file to include a mapping such as "ahostname 127.0.0.2", I could to that, but I don't want to update that file.

Is there an api I can use to create these mappings on the fly (without modifying the hosts file)? And, if so, can you give me a small example of doing it in c++, vb, or (preferably) C#?

Note that I cannot use a DNS server for this purpose - it would all have to be done on the Windows client. It looks like another way to ask my question is:

Is it possible to programmatically update the DNS client resolver cache.

Thanks,
David

Answer : In Windows, is there a way to map hostnames to IP addresses programatically?

Bear in mind that if you are intending on running your finished program on a client workstation (PC) that has any of the major brand anti-virus/personal firewall programs installed then your attempts to manipulate DNS Cache or the Hosts file will (well it should) trigger an alert and probably stop execution of your code.

Assuming the client PC's will have Internet connectivity and are able to perfrom normal DNS lookups - why don't you set  up an account on one of the free public DNS hosting services (such dyndns.org) with some domain names that you want to use in your code and then set them with the local IP addresses of your choice.

In this way you don't need to play around with the client PC's DNS Cache or Host file - that even if allowed - could create other problems not related to your code for that user PC in the future.
Random Solutions  
 
programming4us programming4us