<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://w.rkdrm.com/index.php?action=history&amp;feed=atom&amp;title=One_Computer%2C_Many_IP_Addresses</id>
		<title>One Computer, Many IP Addresses - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://w.rkdrm.com/index.php?action=history&amp;feed=atom&amp;title=One_Computer%2C_Many_IP_Addresses"/>
		<link rel="alternate" type="text/html" href="http://w.rkdrm.com/index.php?title=One_Computer,_Many_IP_Addresses&amp;action=history"/>
		<updated>2026-06-22T08:15:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.25.2</generator>

	<entry>
		<id>http://w.rkdrm.com/index.php?title=One_Computer,_Many_IP_Addresses&amp;diff=611&amp;oldid=prev</id>
		<title>Rkdrm: New page: You might want to test a load-balanced website, that is generate load from a bunch of different source IP addresses. Microsoft Test Load Agent product can do this, but it isn&#039;t covered by ...</title>
		<link rel="alternate" type="text/html" href="http://w.rkdrm.com/index.php?title=One_Computer,_Many_IP_Addresses&amp;diff=611&amp;oldid=prev"/>
				<updated>2010-10-14T07:19:46Z</updated>
		
		<summary type="html">&lt;p&gt;New page: You might want to test a load-balanced website, that is generate load from a bunch of different source IP addresses. Microsoft Test Load Agent product can do this, but it isn&amp;#039;t covered by ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;You might want to test a load-balanced website, that is generate load from a bunch of different source IP addresses. Microsoft Test Load Agent product can do this, but it isn&amp;#039;t covered by MSDN subscritption and we don&amp;#039;t have it.&lt;br /&gt;
&lt;br /&gt;
It turns out you can generate a bunch of source IP addresses on any client machine, even if it has only a single NIC card. And you can initiate requests within normal Visual Studio web test via your own extension. &lt;br /&gt;
&lt;br /&gt;
First you need to configure a bunch of static IPs on your machine with the normal Windows IPV4 Protocol Advanced Properties dialog on the network manager thingy - make sure you don&amp;#039;t clash with other IPs on your network. You can then attach HttpWebRequests to each of those IP addresses in code.&lt;br /&gt;
&lt;br /&gt;
The key is to use the ServicePointManager (System.Net) to obtain a ServicePoint endpoint on an IP address you&amp;#039;ve configured on your machine. Details are given in http://www.devnewsgroups.net/dotnetframework/t31841-invoke-httpwebrequest-specific-ip-card-how.aspx&lt;br /&gt;
&lt;br /&gt;
Example is (change the example IP &amp;quot;192.168.2.102&amp;quot; below to match one you&amp;#039;ve configured):&lt;br /&gt;
&lt;br /&gt;
 static void Get(Uri uri)&lt;br /&gt;
 {&lt;br /&gt;
  HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);&lt;br /&gt;
  request.UserAgent =&lt;br /&gt;
    &amp;quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7.8) &amp;quot; +&lt;br /&gt;
    &amp;quot;Gecko/20050511 Firefox/1.0.4&amp;quot;;&lt;br /&gt;
  ServicePoint servicePoint = &lt;br /&gt;
    ServicePointManager.FindServicePoint(uri);&lt;br /&gt;
  servicePoint.BindIPEndPointDelegate = new BindIPEndPoint(Bind);&lt;br /&gt;
  using (MemoryStream memoryStream = new MemoryStream(0x10000))&lt;br /&gt;
  using (HttpWebResponse response = &lt;br /&gt;
   (HttpWebResponse) request.GetResponse())&lt;br /&gt;
  using (Stream responseStream = response.GetResponseStream())&lt;br /&gt;
  {&lt;br /&gt;
    // Add a breakpoint on the next line. When the breakpoint is &lt;br /&gt;
    // being hit, do a &amp;quot;netstat -p tcp&amp;quot; on a command line and &lt;br /&gt;
    // verify that port 8888 is being used.&lt;br /&gt;
    byte[] buffer = new byte[0x1000];&lt;br /&gt;
    int bytes;&lt;br /&gt;
    while ((bytes = responseStream.Read(buffer, 0, buffer.Length)) &amp;gt; 0)&lt;br /&gt;
    {&lt;br /&gt;
      memoryStream.Write(buffer, 0, bytes);&lt;br /&gt;
    }&lt;br /&gt;
    string text = Encoding.UTF8.GetString(memoryStream.ToArray());&lt;br /&gt;
    Console.WriteLine(text);&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
 static IPEndPoint Bind(ServicePoint servicePoint, IPEndPoint   &lt;br /&gt;
  remoteEndPoint, int retryCount) &lt;br /&gt;
 {&lt;br /&gt;
  IPAddress address = IPAddress.Parse(&amp;quot;192.168.2.102&amp;quot;);&lt;br /&gt;
  return new IPEndPoint(address, 8888);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
Key fragments to do this in a web test (well, the whole thing, really) are:&lt;br /&gt;
        &lt;br /&gt;
    //========================================================================&lt;br /&gt;
    public class IpCycleTestHelper&lt;br /&gt;
    {&lt;br /&gt;
        private int _testNumber = 0;&lt;br /&gt;
        private string[] _ipAddresses;&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public IpCycleTestHelper()&lt;br /&gt;
        {&lt;br /&gt;
            _ipAddresses = GetLocalIpAddresses();&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        private static string[] GetLocalIpAddresses()&lt;br /&gt;
        {&lt;br /&gt;
            List&amp;lt;string&amp;gt; result = new List&amp;lt;string&amp;gt;();&lt;br /&gt;
            string localHostName = Dns.GetHostName();&lt;br /&gt;
            IPHostEntry hostEntry = Dns.GetHostEntry(localHostName);&lt;br /&gt;
            foreach (IPAddress ipAddr in hostEntry.AddressList)&lt;br /&gt;
            {&lt;br /&gt;
                Debug.Print(&amp;quot;Found local IP = {0}&amp;quot;, ipAddr.ToString());&lt;br /&gt;
                result.Add(ipAddr.ToString());&lt;br /&gt;
            }&lt;br /&gt;
            return result.ToArray();&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public int GetNextTestNumber()&lt;br /&gt;
        {&lt;br /&gt;
            _testNumber++;&lt;br /&gt;
            return _testNumber;&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public string GetNextIpAddress()&lt;br /&gt;
        {&lt;br /&gt;
            int ipIndex = _testNumber % _ipAddresses.Length;&lt;br /&gt;
            return _ipAddresses[ipIndex];&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 public class IpCycleWebTestPlugin : WebTestPlugin&lt;br /&gt;
    {&lt;br /&gt;
        private const string TEST_CONTEXT_NAME = &amp;quot;Test Context&amp;quot;;&lt;br /&gt;
        private const int MAX_BIND_RETRIES = 100;&lt;br /&gt;
        private static IpCycleTestHelper _ipCycleTestHelper = new IpCycleTestHelper();&lt;br /&gt;
        //====================================================================&lt;br /&gt;
        private class TestContext&lt;br /&gt;
        {&lt;br /&gt;
            public int TestNumber { get; set; }&lt;br /&gt;
            public string IpAddress { get; set; }&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        private TestContext GetTestContext(WebTest webTest)&lt;br /&gt;
        {&lt;br /&gt;
            if (!webTest.Context.ContainsKey(TEST_CONTEXT_NAME))&lt;br /&gt;
            {&lt;br /&gt;
                webTest.Context.Add(TEST_CONTEXT_NAME, new TestContext());&lt;br /&gt;
            }&lt;br /&gt;
            return webTest.Context[TEST_CONTEXT_NAME] as TestContext;&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public override void PreWebTest(object sender, PreWebTestEventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            base.PreWebTest(sender, e);&lt;br /&gt;
            TestContext testContext = GetTestContext(e.WebTest);&lt;br /&gt;
            testContext.TestNumber = _ipCycleTestHelper.GetNextTestNumber();&lt;br /&gt;
            testContext.IpAddress = _ipCycleTestHelper.GetNextIpAddress();&lt;br /&gt;
            Debug.Print(&amp;quot;Starting Web Test {0}&amp;quot;, testContext.TestNumber);&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public override void PreRequest(object sender, PreRequestEventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            base.PreRequest(sender, e);&lt;br /&gt;
            TestContext testContext = GetTestContext(e.WebTest);&lt;br /&gt;
            Debug.Print(&amp;quot;Binding request, test = {0}, IP = {1}, request = {2}&amp;quot;, testContext.TestNumber, testContext.IpAddress, e.Request.Url);&lt;br /&gt;
            ServicePoint servicePoint = ServicePointManager.FindServicePoint(e.Request.Url, e.WebTest.WebProxy);&lt;br /&gt;
            if (servicePoint != null &amp;amp;&amp;amp; servicePoint.BindIPEndPointDelegate == null)&lt;br /&gt;
            {&lt;br /&gt;
                servicePoint.BindIPEndPointDelegate = new BindIPEndPoint(delegate(ServicePoint sp, IPEndPoint ep, int retryCount)&lt;br /&gt;
                {&lt;br /&gt;
                    if (retryCount == MAX_BIND_RETRIES)&lt;br /&gt;
                    {&lt;br /&gt;
                        Debug.Print(&amp;quot;** Binding aborted after {0} attempts! test = {1}, IP = {2}, request = {3}&amp;quot;, MAX_BIND_RETRIES, testContext.TestNumber, testContext.IpAddress, e.Request.Url);&lt;br /&gt;
                        return null;&lt;br /&gt;
                    }&lt;br /&gt;
                    IPAddress address = IPAddress.Parse(testContext.IpAddress);&lt;br /&gt;
                    return new IPEndPoint(address, 0);&lt;br /&gt;
                });&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        //--------------------------------------------------------------------&lt;br /&gt;
        public override void PostRequest(object sender, PostRequestEventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            base.PostRequest(sender, e);&lt;br /&gt;
            ServicePoint servicePoint = ServicePointManager.FindServicePoint(e.Request.Url, e.WebTest.WebProxy);&lt;br /&gt;
            if (servicePoint != null)&lt;br /&gt;
            {&lt;br /&gt;
                servicePoint.BindIPEndPointDelegate = null;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Rkdrm</name></author>	</entry>

	</feed>