Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- namespace ipconnect
- {
- class Program
- {
- class MySocket
- {
- public static int totalBytesReceived;
- public static string SERV = "foxtaur.furnet.org";
- public static int PORT = 6667;
- public static string NICK;
- public static string PASS;
- public static string USER;
- public static byte[] receivedBytes;
- public static byte[] ByteBuffer;
- public static IPHostEntry ipHost;
- public static IPAddress ipAddress;
- public static IPEndPoint ipEndPoint;
- public static Socket sender = new Socket(AddressFamily.InterNetwork,
- SocketType.Stream,
- ProtocolType.Tcp);
- }
- class CTCP
- {
- public static void VER()
- {
- MySocket.sender.Send(Encoding.ASCII.GetBytes("VERSION R-IRCv0.0 " + System.Environment.OSVersion.ToString() + " RoxFox64(On IRC)\x0D\x0A"));
- }
- }
- static void collect_Data()
- {
- Console.WriteLine("Please type the server to connect to:");
- MySocket.SERV = Console.ReadLine();
- Console.WriteLine("Please type your username:");
- MySocket.USER = Console.ReadLine();
- Console.WriteLine("Please type your nickname:");
- MySocket.NICK = Console.ReadLine();
- Console.WriteLine("Please type your password(Press [Enter] if there isn't one):");
- MySocket.PASS = Console.ReadLine();
- }
- static int connect()
- {
- MySocket.receivedBytes = new byte[1024];
- MySocket.ByteBuffer = new byte[1024];
- Console.WriteLine("Resolving Host...");
- try
- {
- MySocket.ipHost = Dns.Resolve(MySocket.SERV);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex.Message);
- return 0;
- }
- Console.WriteLine("Looking up irc.furnet.org");
- MySocket.ipAddress = MySocket.ipHost.AddressList[0];
- MySocket.ipEndPoint = new IPEndPoint(MySocket.ipAddress, MySocket.PORT);
- Console.WriteLine("Connecting to irc.furnet.org ({0})", MySocket.sender.RemoteEndPoint);
- try
- {
- MySocket.sender.Connect(MySocket.ipEndPoint);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- return 0;
- }
- Console.WriteLine("Connected!");
- return 1;
- }
- static void Register()
- {
- if (MySocket.sender.Connected)
- {
- if (MySocket.PASS != "")
- {
- byte[] PASS = Encoding.ASCII.GetBytes("PASS " + MySocket.PASS);
- MySocket.sender.Send(PASS);
- }
- byte[] NICK = Encoding.ASCII.GetBytes("NICK " + MySocket.NICK);
- MySocket.sender.Send(NICK);
- byte[] USER = Encoding.ASCII.GetBytes("USER " + MySocket.USER + " 3 * :R-IRC User");
- MySocket.sender.Send(USER);
- }
- }
- static void Update()
- {
- if (MySocket.sender.Connected)
- {
- MySocket.totalBytesReceived = MySocket.sender.Receive(MySocket.ByteBuffer);
- MySocket.ByteBuffer.CopyTo(MySocket.receivedBytes, 0);
- Console.WriteLine("{0}", Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived));
- if (Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Contains("NOTICE AUTH :*** Checking ident..."))
- {
- if (MySocket.PASS != "")
- {
- MySocket.sender.Send(Encoding.ASCII.GetBytes("PASS " + MySocket.PASS + " \x0D\x0A"));
- }
- MySocket.sender.Send(Encoding.ASCII.GetBytes("USER " + MySocket.USER + " 3 * :R-IRC User \x0D\x0A"));
- MySocket.sender.Send(Encoding.ASCII.GetBytes("NICK " + MySocket.NICK + " \x0D\x0A"));
- Console.WriteLine("Sending User Info...");
- }
- else if (Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Contains("PING :"))
- {
- Console.WriteLine("Obtained ping request!\n" + "Replying...");
- int len = Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Length;
- string POC = Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Substring(len - 8, 8);
- MySocket.sender.Send(Encoding.ASCII.GetBytes("PONG :" + POC + "\x0D\x0A"));
- }
- else if (Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Contains("VERSION"))
- {
- CTCP.VER();
- }
- }
- }
- static void Main(string[] args)
- {
- collect_Data();
- connect();
- while (true)
- {
- Update();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement