0
votes

Using the windows host file located in

windows/system32/drivers/etc/host

Is it possible to respond a request from an application like when it is offline(not connected to the Internet)? Could you please give an example of this is done.

3
can you be more specific in what you want to simulate? What is offline and who is going to reply?Andrey Marchuk

3 Answers

1
votes

The hosts file only lists aliases for ip-addresses. For example:

192.168.0.1     foo bar foo.com bar.com

If that line is in the hosts file, then you can use the host-names foo, bar, foo.com and bar.com to reach the computer with ip-address 192.168.0.1.

If the computer, or the service you want to reach on that address, is not online, you can't reach it no matter what you have in your hosts file.

0
votes

If you mean to respond to HTTP requests then you need a Web Server configured to respond to any host (or that specific host name) on port 80. If you are not using it for anything else IIS can do this1 – configure it to return 404 (not found) or some other relatively neutral fail response.


1 If IIS is already being used then things get much harder, later versions of IIS are more flexible either with a combination of using HTTP.SYS to allow other applications to respond to certain URLs or using different Web Sites in IIS (until Windows 7, or maybe Vista, only available on Server editions of Windows).

0
votes

If you are willing to map your local development environment to a domain name, you can edit the domain name in hosts file and map it to 127.0.0.1, which is the loopback address.

That way, any requests done to that particular domain will fallback to your local machine.

You can also assign different LAN/WAN IP addresses.

When your development phase is done, you can remove the entry.

I would not recommend doing so, stick with the localhost and just make use of that to test virtualhosts setup or some sort of domain based configurations.

If there is anything else I can answer, please don't hesitate to post further comments on my answer.