Public Class IRC_Bot
' Channel Moderators
Public Shared Gods As String() = "Elektro Elektro-H Elektro-H_ Drvy kili4n Ikillnukes Caster_ OmarHack OmarHack_ Carloswaldo _0xDani".Split(ChrW(32)).ToArray
' Commands
Private Shared Line As String = Nothing
Private Shared Name As String = Nothing
Private Shared IP As String = Nothing
Private Shared Command As String = Nothing
Private Shared Argument As String = Nothing
' Bot Status
Public Shared Activated As Boolean = True
Private Shared Elapsed_Time As New Stopwatch
Private Shared Total_Messages As Int64 = 0
' Connection
Private Shared Ident_Listener As Net.Sockets.TcpListener = Nothing
Private Shared Ident_Client As Net.Sockets.TcpClient = Nothing
Private Shared Ident_NetworkStream As Net.Sockets.NetworkStream = Nothing
Private Shared Ident_Reader As IO.StreamReader = Nothing
Private Shared Ident_Writer As IO.StreamWriter = Nothing
Private Shared Ident_ResponseString As String = Nothing
Private Shared TCP_client As Net.Sockets.TcpClient = Nothing ' Main connection to the IRC network.
Private Shared Network_Stream As Net.Sockets.NetworkStream = Nothing ' Break TCP connection down to a network stream.
Private Shared IRC_Reader As IO.StreamReader = Nothing ' Stream to read messages from the Server.
Private Shared IRC_Writer As IO.StreamWriter = Nothing ' Stream to write messages to the server.
' To attach Console (If needed)
' Private Declare Function AllocConsole Lib "kernel32.dll" () As Boolean
Public Shared Sub Connect(ByVal Server As String, _
ByVal Channel As String, _
ByVal NickName As String, _
Optional ByVal Port As Int32 = 6667, _
Optional ByVal RealName As String = "ElektroBot", _
Optional ByVal UserName As String = "ElektroHacker")
' AllocConsole() ' Attach Console (If needed)
' Change CMD Window Size
Console.SetWindowSize(200, 60)
Try
' Create Connection
Write("Creating Connection...", ConsoleColor.Yellow)
TCP_client = New Net.Sockets.TcpClient(Server, Port)
Network_Stream = TCP_client.GetStream
IRC_Reader = New IO.StreamReader(Network_Stream)
IRC_Writer = New IO.StreamWriter(Network_Stream)
If Not IRC_Writer.AutoFlush Then IRC_Writer.AutoFlush = True
' Set name
Write("Setting up name...", ConsoleColor.Yellow)
IRC_Writer.WriteLine(String.Format("USER {0} {1} * :{2}", UserName, 0, RealName))
' Set Nickname
Write("Setting Nickname...", ConsoleColor.Yellow)
IRC_Writer.WriteLine(String.Format("NICK {0}", NickName))
' Join Room
Write("Joining Room...", ConsoleColor.Yellow)
IRC_Writer.WriteLine(String.Format("JOIN {0}", Channel))
' Check Ident connection
Write("Checking Ident connection...", ConsoleColor.Yellow)
Ident_Listener = New Net.Sockets.TcpListener(Net.IPAddress.Any, 113)
Ident_Listener.Start()
Ident_Client = Ident_Listener.AcceptTcpClient
Ident_Listener.Stop()
Ident_NetworkStream = Ident_Client.GetStream
Ident_Reader = New IO.StreamReader(Ident_NetworkStream)
Ident_ResponseString = Ident_Reader.ReadLine
Write("Ident got: " & Ident_ResponseString, ConsoleColor.Cyan)
Ident_Writer = New IO.StreamWriter(Ident_NetworkStream)
If Not Ident_Writer.AutoFlush Then Ident_Writer.AutoFlush = True
Ident_Writer.WriteLine(String.Format("{0} : USERID : WINDOWS 7 : {1}", Ident_ResponseString, UserName))
' Read messages
Write("Reading messages...", ConsoleColor.Yellow)
Elapsed_Time.Start()
While True
' Sum the total received messages
Total_Messages += 1
' Get the IRC line to read
Line = IRC_Reader.ReadLine
' Print the IRC line
Write(Line, ConsoleColor.Gray)
' Get User Name
Try : Name = Line.Split("!").First.Substring(1, Line.Split("!").First.Length - 1)
Catch : Name = Nothing
End Try
' Get User IP
Try : IP = Line.Split(" ").First.Split("/").Last.Replace("ip.", "")
Catch : IP = Nothing
End Try
' Get User Command
Try : Command = Line.Split(" ")(3).Substring(1, Line.Split(" ")(3).Length - 1).ToLower
Catch : Command = Nothing
End Try
' Get the command argument
Try : Argument = Line.Split(" ")(4)
Catch : Argument = Nothing
End Try
' IRC Ping-Pong
if line.tolower.startswith("ping") then
Write("Answering Ping with Pong...", ConsoleColor.Yellow)
Write("PONG " & Line, ConsoleColor.Cyan)
IRC_Writer.WriteLine("PONG " & Line)
end if
' Parse commands
Select Case Command
' Help
Case "!?", "!ayuda"
If Line.ToLower.Contains(Channel.ToLower) Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} ", Name, "[+] Comandos públicos:"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!? | !ayuda ", "Muestra esta ayuda."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!reglas ", "Muestra las reglas de la sala."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!reglasehn ", "Muestra las reglas de ElHacker.Net."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!status ", "Muestra el estado del Bot."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!Whois (IP) ", "Muestra información geográfica de una IP."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} ", Name, "[+] Comandos privados:"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!op ", "Te otorga el estado de OP."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!op(+|-) (NOMBRE)", "Otorga o elimina el estado de OP a un usuario."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!bot (ON|OFF) ", "Activa o Desactiva el Bot."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} | {2}", Name, "!q | !quit ", "Desconecta al Bot."))
End If
' Room Rules
Case "!reglas"
If Line.ToLower.Contains(Channel.ToLower) Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1}", Name, "[+] Reglas de " & Channel))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1}", Name, "1. Respetar a los usuarios y no ofender de ninguna manera."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1}", Name, "2. No preguntar como puedes hackear a personas ajenas."))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1}", Name, "3. No compartir material pornográfico o difundir la pederástia o cosas parecidas."))
End If
' EHN Rules
Case "!reglasehn"
If Line.ToLower.Contains(Channel.ToLower) Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1}", Name, "[+] Reglas de ElHacker.Net: http://foro.elhacker.net/reglas"))
End If
' Geo-Locate IP
Case "!whois"
'If Line.ToLower.Contains(Channel.ToLower) Then _
'AndAlso Activated Then
'Dim GeoInfo As GeoLocation.GeoInfo = GeoLocation.Locate(Argument)
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "[+] Información geográfica de ", Argument))
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "País..:", GeoInfo.Country))
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Ciudad:", GeoInfo.City))
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Código:", GeoInfo.Code))
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Host..:", GeoInfo.Host))
'IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Ip....:", GeoInfo.Ip))
'GeoInfo = Nothing
' End If
' Give own OP+
Case "!op"
If Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine(String.Format("MODE {0} +o {1}", Channel, Name))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2}", Channel, Name, "se ha convertido en OP."))
ElseIf Not Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2}", Channel, Name, "no tienes privilegios para ser OP."))
End If
' Give Op+ to a user
Case "!op+"
If Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine("MODE {0} +o {1}", Channel, Argument)
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2} {3}", Channel, Name, "concedió OP a", Argument))
ElseIf Not Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2}", Channel, Name, "no tienes privilegios para conceder OP."))
End If
' Give Op- to a user
Case "!op-"
If Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine("MODE {0} -o {1}", Channel, Argument)
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2} {3}", Channel, Name, "denegó OP a", Argument))
ElseIf Not Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2}", Channel, Name, "no tienes privilegios para denegar OP."))
End If
' Bot ON/OFF
Case "!bot"
If Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) Then
Select Case Argument.ToLower
Case "on"
Activated = True
Write("Bot status changed to: Enabled", ConsoleColor.Cyan)
Case "off"
Activated = False
Write("Bot status changed to: Disabled", ConsoleColor.Cyan)
End Select
ElseIf Not Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} :{1} {2}", Channel, Name, "no tienes privilegios de OP."))
End If
' Bot Status
Case "!status"
If Line.ToLower.Contains(Channel.ToLower) Then
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} ", Name, "[+] Status del Bot"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Soy propiedad de......:", "Elektro-H"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Versión de mi sistema.:", "0.2"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Tiempo total online...:", Elapsed_Time.Elapsed.Hours & " H, " & Elapsed_Time.Elapsed.Minutes & " M, " & Elapsed_Time.Elapsed.Seconds & " S"))
IRC_Writer.WriteLine(String.Format("PRIVMSG {0} : {1} {2}", Name, "Mensajes procesados...:", Total_Messages))
End If
' Quit
Case "!q", "!quit"
If Gods.Contains(Name) _
AndAlso Line.ToLower.Contains(Channel.ToLower) _
AndAlso Activated Then
IRC_Writer.WriteLine("QUIT")
Write("Exiting...", ConsoleColor.Yellow)
Exit Sub
End If
End Select
End While
Catch ex As Exception
Write("Error: " & ex.Message, ConsoleColor.Red)
IRC_Writer.WriteLine("QUIT")
Finally
IRC_Reader.Dispose()
IRC_Writer.Dispose()
Network_Stream.Dispose()
End Try
End Sub
Private Shared Sub Write(ByVal Text As String, _
Optional ByVal ForeColor As System.ConsoleColor = ConsoleColor.White, _
Optional ByVal BackColor As System.ConsoleColor = ConsoleColor.Black)
Dim Current_ForegroundColor As ConsoleColor = Console.ForegroundColor
Dim Current_BackgroundColor As ConsoleColor = Console.BackgroundColor
Console.ForegroundColor = ForeColor
Console.BackgroundColor = BackColor
Console.WriteLine(Text & vbNewLine)
Console.ForegroundColor = Current_ForegroundColor
Console.BackgroundColor = Current_BackgroundColor
End Sub
End Class