All pastes #494003 Raw Edit

ELITE CODE HERE

public text v1 · immutable
·published 2007-05-18 01:28 UTC
rendered paste body
/***************************************/
/*NanoIRCBot by nano a.k.a Quan Chi2   */
/*(c) 2007                             */
/***************************************/
/*                                     */
/*    usage: NanoIRCBot <serverip>     */
/*                                     */ 
/***************************************/ 
/* C:\Program Files\Microsoft Visual Studio\MyProjects\NanoIRCBot\Debug */
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <iostream.h>

#define PORT 6667

int main(int argc, char *argv[])
{
	char *nick		= "NICK nanobot\r\n"; //bot name
	char *channel	= "JOIN #social\r\n";  //channel the bot will join
	char *user      = "USER nano d d :nano\r\n";
	char buf[512];
	char outbuf[512];

	if (argc != 2)
	{
		fprintf(stderr,"[-]Usage: NanoIRCBot <serverip>\n");
		exit(1);
	}
/*===========Initialize Winsock and declare connection variables.===========*/
	WSADATA WSAData;
	WSAStartup(MAKEWORD(2,0), &WSAData);  //Winsock 2.0
	SOCKET connection;//this is a socket named 'connection'
	SOCKADDR_IN sin;
	
	connection = socket(AF_INET, SOCK_STREAM, 0); //'connection' is a stream socket


	struct hostent *he;
	if ((he = gethostbyname(argv[1])) == NULL) //get the ip of parameter 1 in command prompt
	{
		perror("gethostbyname"); //if there is a problem in gethostbyname, print the error
		exit(EXIT_FAILURE);
	}

/*=================================Lets Get Busy=============================*/
	int tries;
	for(tries = 1;;tries++)
	{
		sin.sin_addr			= *((struct in_addr *)he->h_addr); //address to connect to
		sin.sin_family			= AF_INET;						   //potocol AF_INET is everything
		sin.sin_port			= htons(PORT);                     //the port the irc server has open for connections
	    
		printf("[-]Connecting...\n");				               //some stupid message.
		Sleep(1000);

		connect(connection, (SOCKADDR*)&sin, sizeof(sin));         //connect to the server
		printf("[-]Connected!\n");
		Sleep(100);

		send(connection,nick,strlen(nick),0);
		printf("%s",nick);
		send(connection,user,strlen(user),0);
		printf("%s",user);

		send(connection,channel,strlen(channel),0);
		printf("%s",channel);
		
		while(1) 
		{
			memset(buf, 0, 512);
			memset(outbuf, 0, 512);
			
			int bRecv;
			bRecv = recv(connection, outbuf, 512, 0);
			if( (bRecv == 0) || (bRecv == SOCKET_ERROR) ) break;
			if(buf[0]!=':') 
			{
				strcpy(outbuf, "PONG :");
				send(connection,buf,strlen(buf),0);
			} 
			else
			{
				exit(1);
			}
		}
		//return EXIT_SUCCESS;
	}
		return 0;
}