• IP地址段遍历


    #region 搜索ftp服务器地址
            /// <summary>
            /// 搜索ftp服务器
            /// </summary>
            public void SearchFtpServer()
            {
     
    var beginIp=""192.168.1.1;
    var endIp=""192.168.1.251;
                var currentIp = IPAddress.Parse(beginIp);
                var endIp = IPAddress.Parse(endIp);
     
                var beginNum = GetIpNumber(currentIp);
                var endNum = GetIpNumber(endIp);
     
                for (long i = beginNum; i <= endNum; i++)
                {
                  //TODO:根据ip地址做事
                    currentIp = NextIP(currentIp);
                }
            }
     
            #region ip地址相关
            /// <summary>
            /// 将ip地址转换为数字表示
            /// </summary>
            /// <param name="ip"></param>
            /// <returns></returns>
            private long GetIpNumber(IPAddress ip)
            {
                var ipBytes = ip.ToString().Split(new char[] { '.' });
                var num = Convert.ToInt64(ipBytes[0]) * 256 * 256 * 256 +
                    Convert.ToInt64(ipBytes[1]) * 256 * 256 +
                    Convert.ToInt64(ipBytes[2]) * 256 +
                    Convert.ToInt64(ipBytes[3]);
                return num;
            }
     
            /// <summary>
            /// 从一个IPAddress 获取它的下一个 IPAddress
            /// </summary>
            /// <param name="theIP"></param>
            /// <returns></returns>
            private IPAddress NextIP(IPAddress theIP)
            {
                byte[] ipBytes = theIP.GetAddressBytes();
                if (ipBytes[3] != 255)
                {
                    ipBytes[3] += 1;
                }
                else if (ipBytes[2] != 255)
                {
                    ipBytes[2] += 1;
                    ipBytes[3] = 1;
                }
                else if (ipBytes[1] != 255)
                {
                    ipBytes[1] += 1;
                    ipBytes[2] = 1;
                    ipBytes[3] = 1;
                }
                else if (ipBytes[0] != 255)
                {
                    ipBytes[0] += 1;
                    ipBytes[1] = 1;
                    ipBytes[2] = 1;
                    ipBytes[3] = 1;
                }
                IPAddress ip = new IPAddress(ipBytes);
     
                return ip;
            }
            #endregion
  • 相关阅读:
    sql 计算auc
    tf.app.flags
    transformer
    python 直连 hive
    rnn 详解
    yolov3
    记学习react-native
    html5横、竖屏状态 以及禁止横屏
    图片懒加载
    npm安装的时候报-4048
  • 原文地址:https://www.cnblogs.com/maomao999/p/3668400.html
Copyright © 2020-2023  润新知