• C# 输入ip段生成ip地址


    具体代码如下:

    private void button1_Click(object sender, EventArgs e)
            {
                string StartIp = "";
                string EndIp = "";
                StartIp = Startinput.Text;
                EndIp = Endinput.Text;
                uint iStartip = ipTint(StartIp);
                uint iEndIp = ipTint(EndIp);
                //string ip_result="";
                StringBuilder ip_result=new StringBuilder();
                if (iEndIp >= iStartip)
                {
                    for (uint ip = iStartip; ip <= iEndIp; ip++)
                    {
                        ip_result.Append(intTip(ip)).Append(" ");
                        //ip_result = ip_result + intTip(ip)+" ";
                    }
                    resultTextBox.Text = ip_result.ToString();   //RichTextBox
                }
                else
                {
                    MessageBox.Show("天啊,起始ip居然比终止ip还大");
                }
            }
            public static uint ipTint(string ipStr)
            {
                string[] ip = ipStr.Split('.');
                uint ipcode = 0xFFFFFF00 | byte.Parse(ip[3]);
                ipcode = ipcode & 0xFFFF00FF | (uint.Parse(ip[2]) << 0x8);
                ipcode = ipcode & 0xFF00FFFF | (uint.Parse(ip[1]) << 0xF);
                ipcode = ipcode & 0x00FFFFFF | (uint.Parse(ip[0]) << 0x18);
                return ipcode;
            }
            public static string intTip(uint ipcode)
            {
                byte a = (byte)((ipcode & 0xFF000000) >> 0x18);
                byte b = (byte)((ipcode & 0x00FF0000) >> 0xF);
                byte c = (byte)((ipcode & 0x0000FF00) >> 0x8);
                byte d = (byte)(ipcode & 0x000000FF);
                string ipStr = string.Format("{0}.{1}.{2}.{3}", a, b, c, d);
                return ipStr;
            }

    参考地址:http://blog.csdn.net/dolphin_h/article/details/38726613

  • 相关阅读:
    a[::-1]相当于 a[-1:-len(a)-1:-1],也就是从最后一个元素到第一个元素复制一遍。
    +=
    map 和reduce
    赋值语句
    高阶函数
    函数式编程
    迭代器
    如何判断一个对象是可迭代对象呢?方法是通过collections模块的Iterable类型判断:
    ie11升级的过程中遇到的问题以及解决办法
    .csporj 文件部分节点解析
  • 原文地址:https://www.cnblogs.com/louby/p/5983440.html
Copyright © 2020-2023  润新知