Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4626956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:29:48+00:00 2026-05-22T03:29:48+00:00

I have some wrapper code that runs a set of NUnit tests that scan

  • 0

I have some wrapper code that runs a set of NUnit tests that scan live websites for certain response codes.

I’d like to run these tests against a different server. When running manually, I can do this by editing the /etc/hosts file in Windows\System32\drivers and temporarily setting http://www.mysite.com to 10.0.0.whatever

Is there any way I can do the same within a .NET console application – temporarily override a DNS record or somehow intercept the resolution and return a different IP address?

EDIT: This is for testing multiple servers in a web farm. I have three live servers, all of which THINK they are http://www.example.com. Because the servers use HTTP host headers, I can’t just run a test against server1, then server2, then server3, because an HTTP request to http://server1/ will NOT return the same thing as a request to http://www.example.com/ that’s resolved to server1…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:29:49+00:00Added an answer on May 22, 2026 at 3:29 am

    In the past with C++ I was able to hook to the WSOCK32.DLL’s gethostbyname function and reroute DNS requests. I used the Microsoft Detours library to do that.

    As for C# I found this: http://easyhook.codeplex.com/ maybe it will help you. Basically you can hook to the gethostbyname windows function and execute your own code or return a different result (different IP).

    The other possible solution is to temporarily (and programatically) edit the hosts file when the application starts and ends. From your own code.

    EDIT: I found my old C++ code, maybe it will give you a hint what to do.

    struct hostent FAR * WSAAPI MyGetHostByName(IN const char FAR * name)
    {
        // Call the regular function 
        struct hostent* ret = GetHostByNameFunction(name);
        // Check if it's the hostname you want to reroute
        if ( strcmp(host, (char*)name) == 0 )
        {
            // Edit the IP returned by the regular gethostbyname
            ret->h_addr_list[0] = hostIP;
            ret->h_length = 15;
        }
        // Return the result
        return ret;
    }
    

    EDIT2: Found another link with newer release of easyhooks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some written a number of unit tests that test a wrapper around
I have some code in C# which has a com wrapper. This com wrapper
I have some code that I am trying to make it play nicely with
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I have heard mention that some desktop applications are pretty much just wrappers for
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.