Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to logoff USB-Stick from WindowsXP by C#? Pin
Douglas Troy15-Feb-06 5:38
Douglas Troy15-Feb-06 5:38 
QuestionARX Tutorials needed Pin
rukmaj14-Feb-06 21:11
rukmaj14-Feb-06 21:11 
AnswerRe: ARX Tutorials needed Pin
zhok3-Jun-06 11:41
zhok3-Jun-06 11:41 
QuestionIP List Pin
krieg3814-Feb-06 20:53
krieg3814-Feb-06 20:53 
QuestionRe: IP List Pin
leppie14-Feb-06 21:07
leppie14-Feb-06 21:07 
AnswerRe: IP List Pin
krieg3814-Feb-06 21:53
krieg3814-Feb-06 21:53 
GeneralRe: IP List Pin
Dario Solera14-Feb-06 22:38
Dario Solera14-Feb-06 22:38 
AnswerRe: IP List Pin
J4amieC15-Feb-06 0:49
J4amieC15-Feb-06 0:49 
I had a go at this for you, and got it to work, but there were plenty of weirdnesses!

IPAddress has a constructor that looks like:

IPAddress(byte[] address)

Which kept throwing an exception when passed the return from IPAddress.GetAddressBytes - this is weird as all the docs say it should work. There is a weird limitation that requires the byte array to have a length og 16 but II ensured this....

So anyway, IPAddress.Parse was working so a quick method such as the following gets round the issue.

private IPAddress IPFromBytes(byte[] bytes)
{
	return IPAddress.Parse( String.Format("{0}.{1}.{2}.{3}",bytes[0],bytes[1],bytes[2],bytes[3]) );
}


Now, to solve this problem I started by thinking about how to incremement an IPAddress, and I came up with this:

Loop from the last digit to the first
if the current number is 255 set it to 0
otherwise incremement the number and break out the loop

this should cause the sequence to go

127.0.0.1
127.0.0.2
......
127.0.0.254
127.0.0.255
127.0.1.0
127.0.1.1

Here is the incremement code:

private byte[] Incremement(byte[] current)
{
	for(int i=3;i>-1;i--)
	{
		if(current[i] == 255)
		{
			current[i] = 0;
		}
		else
		{
			current[i]++;
			break;
		}
	}
	return current;
}


Finally, the get range method must do the following

capture start and end IP's
loop while not at end
capture current IP into a list
incremement IP

The only hard part there is "loop while not at end", as weve already written the incremement and capturing to a list is childs play.

private System.Net.IPAddress [] GetRange(IPAddress start, IPAddress end)
{
	byte[] startBytes = start.GetAddressBytes();
	byte[] endBytes = end.GetAddressBytes();

	byte[] currentBytes = startBytes;

	ArrayList list = new ArrayList();
	
	while(
		currentBytes[0] < endBytes[0]
		|| currentBytes[1] < endBytes[1]
		|| currentBytes[2] < endBytes[2]
		|| currentBytes[3] < endBytes[3])
	{
		list.Add( IPFromBytes(currentBytes) );

		currentBytes = this.Incremement(currentBytes);
	}

	return (IPAddress[])list.ToArray(typeof(IPAddress));
}


Hope it helps, and please rememeber not to be doing anything malicious with port scanners!
GeneralRe: IP List Pin
krieg3815-Feb-06 17:50
krieg3815-Feb-06 17:50 
QuestionLoad an assembly dynamically in a new App Domain Pin
KaurGurpreet14-Feb-06 20:36
KaurGurpreet14-Feb-06 20:36 
AnswerRe: Load an assembly dynamically in a new App Domain Pin
CWIZO14-Feb-06 20:52
CWIZO14-Feb-06 20:52 
GeneralRe: Load an assembly dynamically in a new App Domain Pin
KaurGurpreet14-Feb-06 21:10
KaurGurpreet14-Feb-06 21:10 
GeneralRe: Load an assembly dynamically in a new App Domain Pin
CWIZO14-Feb-06 21:18
CWIZO14-Feb-06 21:18 
GeneralRe: Load an assembly dynamically in a new App Domain Pin
KaurGurpreet14-Feb-06 21:38
KaurGurpreet14-Feb-06 21:38 
AnswerRe: Load an assembly dynamically in a new App Domain Pin
leppie14-Feb-06 21:05
leppie14-Feb-06 21:05 
Questiontab Pin
fmardani14-Feb-06 19:53
fmardani14-Feb-06 19:53 
AnswerRe: tab Pin
CWIZO14-Feb-06 20:57
CWIZO14-Feb-06 20:57 
QuestionCrystal Report: indentation for text field only Pin
levik200614-Feb-06 19:45
levik200614-Feb-06 19:45 
AnswerCrystal Report: indentation for text field only Pin
levik200620-Feb-06 23:06
levik200620-Feb-06 23:06 
Questiongraphics Pin
Vineet Rajan14-Feb-06 19:20
Vineet Rajan14-Feb-06 19:20 
AnswerRe: graphics Pin
CWIZO14-Feb-06 20:57
CWIZO14-Feb-06 20:57 
Questionrunning on slow computers --> UI refreshes too slowly Pin
2hdass14-Feb-06 19:15
2hdass14-Feb-06 19:15 
AnswerRe: running on slow computers --> UI refreshes too slowly Pin
CWIZO14-Feb-06 20:59
CWIZO14-Feb-06 20:59 
QuestionPrinting Data using C# Pin
vkishan14-Feb-06 18:48
vkishan14-Feb-06 18:48 
Questionexcecuting file containin sql script of a database Pin
deep714-Feb-06 18:18
deep714-Feb-06 18:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.