All pastes #638556 Raw Edit

Anonymous

public text v1 · immutable
#638556 ·published 2007-07-29 22:53 UTC
rendered paste body
/*
	cman - coleman port scanner
	authors	:	sunjester, rayb0t
	purpose	:	this application will take an ip address and
				a range of portnumbers and scan each host for
				the portnumbers specified.
*/

#include <stdio.h>
#include <windows.h>
#include <winsock.h>

void DisplayMenu();

int main() {
	//declare variables
	int a, b, c, d, startPortNum, endPortNum, currentPortNum;
	char cUserSelection;

	DisplayMenu();
	
	scanf("%c",&cUserSelection);
	if(cUserSelection == '1') {//if selection 1
	scanf("%d.%d.%d.%d %d-%d",&a, &b, &c, &d, &startPortNum, &endPortNum);
	currentPortNum = startPortNum;//set the current number to the startnumber

	//check for a valid range
	if(a>255 || a<0 || b>255 || b<0 || c>255 || c<0 || d>255 || d<0) {
		printf("Invalid Range!\n");
		return 1;
	}

	//increment our ip values
	while(a <= 255)
	{
		while(b <= 255)
		{
			while(c <= 255)
			{
				while(d <= 255)
				{
					//show current status
					printf("current port: %d\n", currentPortNum);
					printf("current ip  : %d.%d.%d.%d\n", a, b, c, d);

					system("cls");//clear screen
					currentPortNum++;//increment portnumber

					if(currentPortNum == endPortNum) {
						currentPortNum = startPortNum;//reset portnumber
						d++;//increment last number
					}
				}
				d = 0;
				c++;
			}
			c = 0;
			b++;
		}
		b = 0;
		a++;
	}//endwhile
	} else {//end if selection 1
		if(cUserSelection =='2') {//start selection 2
			return 1;//abnormal term
		} else { //end selection 2
			printf("\nInvalid Selection!!\n");
		}//end else
	}

	return 0;//normal termination
}

void DisplayMenu() {
	printf("Welcome to the coleman scanner, choose from the menu below:\n\n");
	printf("\t1. Scan for open ports\n");
	printf("\t2. Exit\n");
	printf("\tSelection: ");
}