• 一种遍历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.../////
    //////////////////////////////

  • 相关阅读:
    设计模式
    DOS批处理脚本
    BAT 批处理脚本 教程
    spring4配置文件详解
    软件过程
    error C2440 “static_cast” 无法从“void (__thiscall C* )(void)...
    error C2065: “IDD_DIALOG1”: 未声明的标识符
    在另一个编辑器中打开
    Github 结合 Hexo 搭建轻量博客
    收藏---wordpress搭建出来的blog
  • 原文地址:https://www.cnblogs.com/sixiweb/p/1786982.html
Copyright © 2020-2023  润新知