Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string errorOctet;
- public bool InvalidOctet(string ip)
- {
- ipErrorNum = 0;
- string[] subOctets = new string[4];
- string[] postContent = new string[4];
- int[] octetCounts = new int[4];
- int[] subOctetNums = new int[4];
- postContent[0] = ip;
- bool addOperation = false;
- int[] iterator = new int[2];
- try
- {
- for (int i = 0; i < 4; i++)
- {
- if (addOperation == true)
- {
- postContent[i] = postContent[i - 1].Replace(subOctets[i - 1], "");
- }
- if (iterator[0] == 3)
- {
- subOctets[i] = postContent[i];
- break;
- }
- octetCounts[i] = postContent[i].IndexOf('.');
- subOctets[i] = postContent[i].Substring(0, octetCounts[i] + 1);
- iterator[0]++;
- addOperation = true;
- }
- for (int i = 0; i < subOctets.Length; i++)
- {
- if (iterator[1] < 3)
- {
- subOctets[i] = subOctets[i].Replace(".", "");
- }
- subOctetNums[i] = Convert.ToInt32(subOctets[i]);
- if (subOctetNums[i] > 255 || subOctetNums[i] < 0)
- {
- ipErrorNum = invalidOctet;
- errorOctet = "octet index = " + (i + 1) + " " + "octet number = " + subOctetNums[i].ToString();
- MessageBox.Show("Invalid IP!");
- return true;
- }
- iterator[1]++;
- }
- MessageBox.Show(subOctets[0] + " | " + subOctets[1] + " | " + subOctets[2] + " | " + subOctets[3]);
- return false;
- }
- catch (Exception ex) { }
- return false;
- }
Add Comment
Please, Sign In to add comment