0% found this document useful (0 votes)
21 views

Summary Description For Class1

This method takes in two IP addresses as strings, parses them, and generates an ArrayList containing all IP addresses in the range between the from and to addresses. It does this by iterating through each octet of the from and to addresses, generating all combinations of IP addresses where the octet values fall between the from and to values.

Uploaded by

karthikinfoindia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Summary Description For Class1

This method takes in two IP addresses as strings, parses them, and generates an ArrayList containing all IP addresses in the range between the from and to addresses. It does this by iterating through each octet of the from and to addresses, generating all combinations of IP addresses where the octet values fall between the from and to values.

Uploaded by

karthikinfoindia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

/// <summary>

/// Summary description for Class1

/// </summary>

public class Class1

private static ArrayList GetIpAdressFromRange(string fromIp, string toIp)

ArrayList ips = new ArrayList();

IPAddress tmpIP = null;

//generate only for valid set of ips

//Todo: check for toip >fromIp

if (IPAddress.TryParse(fromIp, out tmpIP) == true &&


IPAddress.TryParse(toIp, out tmpIP) == true)

string[] fromOct = fromIp.Split('.');

string[] toOct = toIp.Split('.');

string a = null, b = null, c = null, d = null;

int startA = Convert.ToInt32(fromOct[0]);

int startB = Convert.ToInt32(fromOct[1]);


int startC = 1;

int startD = 1;

int endA = Convert.ToInt32(toOct[0]);

int endB = 255;

int endC = 255;

int endD = 255;

for (int intA = startA; intA <= endA; intA++)

a = intA.ToString();

startB = intA == Convert.ToInt32(fromOct[0]) ?


Convert.ToInt32(fromOct[1]) : 1;

endB = intA == Convert.ToInt32(toOct[0]) ?


Convert.ToInt32(toOct[1]) : 255;

for (int intB = startB; intB <= endB; intB++)

b = intB.ToString();

startC = (intA == Convert.ToInt32(fromOct[0])) && (intB ==


Convert.ToInt32(fromOct[1])) ?

Convert.ToInt32(fromOct[2]) : 1;

endC = (intA == Convert.ToInt32(toOct[0])) && (intB ==


Convert.ToInt32(toOct[1])) ?

Convert.ToInt32(toOct[2]) : 255;
for (int intC = startC; intC <= endC; intC++)

c = intC.ToString();

startD = (intA == Convert.ToInt32(fromOct[0])) &&


(intB == Convert.ToInt32(fromOct[1])) && (intC == Convert.ToInt32(fromOct[2]))
?

Convert.ToInt32(fromOct[3]) : 1;

endD = (intA == Convert.ToInt32(toOct[0])) && (intB ==


Convert.ToInt32(toOct[1])) && (intC == Convert.ToInt32(toOct[2])) ?

Convert.ToInt32(toOct[3]) : 255;

for (int intD = startD; intD <= endD; intD++)

d = intD.ToString();

ips.Add(a + "." + b + "." + c + "." + d);

Console.WriteLine(a + "." + b + "." + c + "." +


d);

return ips;

You might also like