I'm working on a project where we want to dynamically change the IP address of where requests are sent to within our app. So for example the first request we send to myWebsite.com goes to 192.168.123.1, the second we want to go to 192.168.123.5, the third to 192.168.123.10.
I know it is possible to achieve this type of functionality via the Windows hosts file located at c:\windows\system32\drivers\etc, however this would require closing the app, changing the file, then openning the app again.
Are there any .Net libraries/techniques available that would allow us to dynamically override the DNS from our code?
Thanks David
I managed to work this out. Using VB.NET:
Dim c As New WebClient
c.Headers.Add("Host", "myWebsite.com")
c.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2")
c.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
c.Headers.Add("Accept-Language", "en-gb,en;q=0.5")
c.Headers.Add("Accept-Encoding", "0")
c.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
Dim s
s = c.DownloadString("http://192.168.123.10/index.aspx")
Setting the Host header is telling IIS which application the request is targetting. This allows us to have the IP address in the URI string of the WebClient object.
Thanks David
I managed to work this out. (as per my above comment).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With