All pastes #520137 Raw Edit

Miscellany

public text v1 · immutable
#520137 ·published 2007-05-29 21:09 UTC
rendered paste body
//-----------------------Includes
#include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <iostream>
//-----------------------

//-----------------------MISC
#pragma comment(lib, "wsock32")
using namespace std;
//-----------------------

void WSA()
{
		//Check WSA
	WSADATA wsaData; // if this doesn't work
		//WSAData wsaData; // then try this instead
		if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
		fprintf(stderr, "WSAStartup failed.\n");
		exit(1);
		}
}


int main()
{
	//Always check WSA :)
	WSA();

	//Variables
	int ret;


	//Connect====================================================================================
	char DEST_IP[25];
	int DEST_PORT = 20;

	cout << "[Socket] IP Please: ";
	cin >> DEST_IP;

	system("CLS");
	cout << "[Socket] Scan On [" << DEST_IP << "] In Progress." << endl;
	
	while(DEST_PORT < 200)
	{
	int sockfd;
		struct sockaddr_in dest_addr; // will hold the destination addr
		sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!

		dest_addr.sin_family = AF_INET; // host byte order
		dest_addr.sin_port = htons(DEST_PORT); // short, network byte order
		dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
		memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
		 
			 ret = connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));

		 //Just an error check, its printing atm
		 if(sockfd == INVALID_SOCKET)	
			cout << "sockfd is not working..." << endl;

		 DEST_PORT+=1;

		 if(ret != -1)
			 cout << "[Socket] Port [" << DEST_PORT << "] = OPEN" << endl;
		 else
			 cout << "[Socket] Port [" << DEST_PORT << "] = CLOSED" << endl;
	}
	//Connect====================================================================================
	shutdown(sockfd, 2); //Close it damnet
		
	cin.get();
}