Hack Forums
[C#] [C#] Simple IRC Bot - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [C#] Simple IRC Bot (/showthread.php?tid=402718)



[C#] Simple IRC Bot - codepoet - May 4, 2010

Coded by Pasi Havia

Code
IrcBot.cs:
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
/*
* This program establishes a connection to irc server, joins a channel and greets every nickname that
* joins the channel.
*
* Coded by Pasi Havia 17.11.2001 http://koti.mbnet.fi/~curupted
*/
class IrcBot
{
// Irc server to connect
public static string SERVER = "irc.df.lth.se";
// Irc server's port (6667 is default port)
private static int PORT = 6667;
// User information defined in RFC 2812 (Internet Relay Chat: Client Protocol) is sent to irc server
private static string USER = "USER CSharpBot 8 * :I'm a C# irc bot";
// Bot's nickname
private static string NICK = "BotNick";
// Channel to join
private static string CHANNEL = "#my_channel";
// StreamWriter is declared here so that PingSender can access it
public static StreamWriter writer;
static void Main (string[] args)
{
NetworkStream stream;
TcpClient irc;
string inputLine;
StreamReader reader;
string nickname;
try
{
irc = new TcpClient (SERVER, PORT);
stream = irc.GetStream ();
reader = new StreamReader (stream);
writer = new StreamWriter (stream);
// Start PingSender thread
PingSender ping = new PingSender ();
ping.Start ();
writer.WriteLine (USER);
writer.Flush ();
writer.WriteLine ("NICK " + NICK);
writer.Flush ();
writer.WriteLine ("JOIN " + CHANNEL);
writer.Flush ();
while (true)
{
while ( (inputLine = reader.ReadLine () ) != null )
{
if (inputLine.EndsWith ("JOIN :" + CHANNEL) )
{
// Parse nickname of person who joined the channel
nickname = inputLine.Substring(1, inputLine.IndexOf ("!") - 1);
// Welcome the nickname to channel by sending a notice
writer.WriteLine ("NOTICE " + nickname + " :Hi " + nickname +
" and welcome to " + CHANNEL + " channel!");
writer.Flush ();
// Sleep to prevent excess flood
Thread.Sleep (2000);
}
}
// Close all streams
writer.Close ();
reader.Close ();
irc.Close ();
}
}
catch (Exception e)
{
// Show the exception, sleep for a while and try to establish a new connection to irc server
Console.WriteLine (e.ToString () );
Thread.Sleep (5000);
string[] argv = { };
Main (argv);
}
}
}
PingSender.cs:
using System;
using System.Threading;
/*
* Class that sends PING to irc server every 15 seconds
*/
class PingSender
{
static string PING = "PING :";
private Thread pingSender;
// Empty constructor makes instance of Thread
public PingSender ()
{
pingSender = new Thread (new ThreadStart (this.Run) );
}
// Starts the thread
public void Start ()
{
pingSender.Start ();
}
// Send PING to irc server every 15 seconds
public void Run ()
{
while (true)
{
IrcBot.writer.WriteLine (PING + IrcBot.SERVER);
IrcBot.writer.Flush ();
Thread.Sleep (15000);
}
}
}

If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3

[img]http://i685.photobucket.com/albums/vv215/blackpearl4/THANKS.gif[/img]



* - Hero - May 4, 2010

What are the commands and how do you make the virus?


* - wesnr - May 4, 2010

(May 4, 2010 08:33 PM)Hero Wrote:  What are the commands and how do you make the virus?

I don't think there are any commands, it's just showing the connection. You'll have to mod your own to make it a botnet bot.


* - codepoet - May 4, 2010

(May 4, 2010 09:12 PM)wesnr Wrote:  I don't think there are any commands, it's just showing the connection. You'll have to mod your own to make it a botnet bot.

correct.......


* - corey - May 4, 2010

(May 4, 2010 08:33 PM)Hero Wrote:  What are the commands and how do you make the virus?

>>What are the commands and how do you make the virus?
>>how do you make the virus?
>>make the virus?
>>the virus?
>>virus?


You need to have a select case/event/if function for data received. Split the data
Code
[command][split][extra data]
Then use how you want

ITT use search plox.


* - codepoet - May 6, 2010

(May 4, 2010 09:20 PM)corey Wrote:  
>>What are the commands and how do you make the virus?
>>how do you make the virus?
>>make the virus?
>>the virus?
>>virus?


You need to have a select case/event/if function for data received. Split the data
Code
[command][split][extra data]
Then use how you want

ITT use search plox.

thats correct..


* - xanphirex - May 6, 2010

LoL you stole this stright from google thats first link when you google c# irc bot its copy and pasted from csharpe corner


* - corey - May 6, 2010

(May 6, 2010 07:24 PM)xanphirex Wrote:  LoL you stole this stright from google thats first link when you google c# irc bot its copy and pasted from csharpe corner

He never said he wrote it, he gave the authors name. Whats wrong?


* - epiphoneultra - May 6, 2010

Why don't you right your own client/server model? it gives you so much control over your virus.


* - codepoet - May 6, 2010

(May 6, 2010 07:24 PM)xanphirex Wrote:  LoL you stole this stright from google thats first link when you google c# irc bot its copy and pasted from csharpe corner

dont flame in my thread....i gave credits!!


* - laptopguy - May 7, 2010

He gave credits, so get off his back. What if people never had the intention of finding out how to make an IRC bot ? People will see this thread and click on it out of curiosity, and learn something. Think outside the box next time. Thanks for this Crow ;)


* - codepoet - May 7, 2010

(May 7, 2010 03:45 PM)kRaeTwin Wrote:  He gave credits, so get off his back. What if people never had the intention of finding out how to make an IRC bot ? People will see this thread and click on it out of curiosity, and learn something. Think outside the box next time. Thanks for this Crow ;)

thanks