C# ip hash算法实现ip分流

      private void button42_Click(object sender, EventArgs e)
        {
            Dictionary<int, string> proxyIpNodes = new Dictionary<int, string>();
            proxyIpNodes.Add(1, "XINNIU_IP_PROXY:XINNIU_IP_PROXY_POOL5");
            proxyIpNodes.Add(2, "XINNIU_IP_PROXY:XINNIU_IP_PROXY_POOL3");

            var ip = textBox5.Text;
            var iphashcode = ip.GetHashCode();

            if (iphashcode < 0) iphashcode = -iphashcode;
            int serverListSize = proxyIpNodes.Count;
            int serverPos = iphashcode % serverListSize;
            
            textBox6.AppendText(proxyIpNodes[serverPos+1]+ System.Environment.NewLine);
        }
原文地址:https://www.cnblogs.com/fangyuan303687320/p/5715968.html