Click here to Skip to main content
15,665,004 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello friend,

i have an problem i have two textbox one is startno and another is endno
and i want insert ip in these text box and when i am click on add button then add all ip in my database for example from [] to [] and when on click on add all ip form 1 to 5 in the database.

i am find the last digit and i am using for loop but i dont know how can i increment in ipno can any one guide me??

Assuming that your text box contains complete IP addresses: "n.n.n.n" then the first thing to do is convert them from strings to IP addresses you can work with. There is a .NET method for this: IPAddress.Parse Method[^]

string s = "";
IPAddress i = IPAddress.Parse(s);
byte[] bytes = i.GetAddressBytes();
for (int count = 0; count < 5; count++)
    i = new IPAddress(bytes);
Share this answer
guptaadeepak 27-Jul-11 4:57am    
Thanks for update but my problem still not solved
OriginalGriff 27-Jul-11 4:58am    
What part of it are you having problems with?
thank griff my problem is solve i am using this
string myString = Txtfrom.Text.ToString();
       char[] separator = new char[] { '.' };
       string[] colorList = myString.Split(separator);
Share this answer

Thanks to OriginalGriff for the part, the complete / dynamic solution would be:

string address1 = "";
string address2 = "";

IPAddress startAddress = IPAddress.Parse(address1);
IPAddress endAddress = IPAddress.Parse(address2);

byte[] startAdrArr = startAddress.GetAddressBytes();
byte[] endAdrArr = endAddress.GetAddressBytes();

for (byte octet1 = startAdrArr[0]; octet1 <= endAdrArr[0]; octet1++)
	for (byte octet2 = startAdrArr[1]; octet2 <= endAdrArr[1]; octet2++)
		for (byte octet3 = startAdrArr[2]; octet3 <= endAdrArr[2]; octet3++)
			for (byte octet4 = startAdrArr[3]; octet4 <= endAdrArr[3]; octet4++)
				string currentAddress = string.Format(
				/* process the address */

Hope this helps anyone :)

Best regards and happy coding,
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900