1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
String ip = "xxx.xxx.xxx.xxx";
String user = "xxxx";
String pass = "xxxx";
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 5038);
clientSocket.Connect(serverEndPoint);
clientSocket.Send(Encoding.ASCII.GetBytes("Action: Login\r\nUsername: " + user + "\r\nSecret: " + pass + "\r\n\r\n"));
int bytesRead = 0;
do {
byte[] buffer = new byte[1024];
bytesRead = clientSocket.Receive(buffer);
string response = Encoding.ASCII.GetString(buffer, 0, bytesRead);
if (Regex.Match(response, "Message: Authentication accepted", RegexOptions.IgnoreCase).Success)
{
msg.Text = "---------- CONNECTE AU SERVEUR " + ip + " ----------";
msg.Refresh();
}
else
{
msg.Text = response;
msg.Refresh();
}
} while (bytesRead != 0);
msg.Text = "Connexion au serveur " + ip + " perdue !";
msg.Refresh();
}
}
} |
Partager