zoukankan      html  css  js  c++  java
  • 一种遍历ip地址段中所有IP的方法。

    这个版本的代码解决了跨网段的问题。但是会多计算出一个网段。

    代码
     /// <summary>
            
    /// Get the next ip by given ip
            
    /// </summary>
            
    /// <param name="nowIP">Given IP(Now IP)</param>
            
    /// <returns>the next ip</returns>
            static IPAddress NextIP(IPAddress nowIP)
            {
                
    byte[] ipBytes = nowIP.GetAddressBytes();
                
    if (ipBytes[3!= 254)
                {
                    ipBytes[
    3+= 1;
                }
                
    else if (ipBytes[2!= 254)
                {
                    ipBytes[
    2+= 1;
                    ipBytes[
    3= 1;
                }
                
    else if (ipBytes[1!= 254)
                {
                    ipBytes[
    1+= 1;
                    ipBytes[
    2= 1;
                    ipBytes[
    3= 1;
                }
                
    else if (ipBytes[0!= 254)
                {
                    ipBytes[
    0+= 1;
                    ipBytes[
    1= 1;
                    ipBytes[
    2= 1;
                    ipBytes[
    3= 1;
                }
                
    else
                {
                    
    // return null;
                    
    //
                }

                IPAddress ip 
    = new IPAddress(ipBytes);

                
    return ip;
            }


    ////////////////////////////////
    ////////Sixi. Let it be.../////
    //////////////////////////////

  • 相关阅读:
    Master公式计算递归时间复杂度
    对数器的使用
    HTML翻转菜单练习
    剑指offer题目解答合集(C++版)
    HTML---仿网易新闻登录页
    两个有序数组中的中位数以及求第k个最小数的值
    算法之重建二叉树
    AFNetWorking 上传功能使用及源码分析
    图片Alpha预乘的作用[转]
    C#/.NET 学习之路——从入门到放弃
  • 原文地址:https://www.cnblogs.com/sixiweb/p/1786982.html
Copyright © 2011-2022 走看看