#include #include #include #include #include #include #include #include #include #define PORT 6667 //IRC port #define MAXDATASIZE 512; int main(argc, char *argv[]) { char *nick = "NICK nanobot\r\n"; //bot nick char *user = "USER nano d d :nano\r\n"; //user char *channel = "JOIN #social\r\n"; //channel if (argc != 2) { fprintf(stderr,"[-]Usage ircbot \n"); exit(1); } int connection, numbytes; char buf[512]; struct hostent *he; struct sockaddr_in sin; if ((he = gethostbyname(argv[1])) == NULL) { herror("gethostbyname"); exit(1); } if ((connection = socket(PF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } sin.sin_family = AF_INET; sin.sin_port = htons(PORT); sin.sin_addr = *((struct in_addr *)he->h_addr); if(connect(connection, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } send(connection, nick, sizeof(buf), 0); send(connection, user, sizeof(buf), 0); while(1) { if ((numbytes = recv(connection, buf, MAXDATASIZE - 1, 0)) == -1) { perror("recv"); exit(1); } if (strncmp("PING", buf, 4) == 0) { printf("Received PING... sending PONG\n"); buf[1] = 'O'; if(send(connection, buf, strlen(buf), 0) == -1) { perror("send"); exit(1); } } }