Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DZ_ip
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             while (true)
  10.             {
  11.                 Console.Write("Введите ip:");
  12.                 string ip = Console.ReadLine();
  13.                 if(NextIP(ip) == null)
  14.                 {
  15.                     Console.WriteLine("Вы ввели неверный IP");
  16.                     continue;
  17.                 }
  18.                 Return(NextIP(ip));
  19.             }
  20.         }
  21.  
  22.         static byte[] NextIP (string ip)
  23.         {
  24.             string[] ipArray = ip.Split('.');
  25.             byte[] ipByte = new byte[ipArray.Length];
  26.             for (int i = 0; i < ipArray.Length; i++)
  27.             {
  28.                 if (Convert.ToInt32(ipArray[i]) > 255)
  29.                 {
  30.                     ipByte = null;
  31.                     break;
  32.                 }
  33.                 ipByte[i] = Convert.ToByte(ipArray[i]);
  34.             }
  35.             return ipByte;
  36.         }
  37.  
  38.         static void Return (byte[] ip)
  39.         {
  40.             for (int i = ip.Length - 1; i >= 0; i--)
  41.             {
  42.                 ip[i] += 1;
  43.                 if(ip[i] != 0)
  44.                 {
  45.                     break;
  46.                 }
  47.             }
  48.             for (int i = 0; i < ip.Length; i++)
  49.             {
  50.                 Console.Write(ip[i] + ".");
  51.             }
  52.             Console.WriteLine();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement