using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
namespace WK
{
/// <summary>
/// 用于向终端发送各播控接口
/// </summary>
class FaSong
{
private static int clientPort = 7001; //终端接收端口
private static int replyPort = 7000; //终端答复端口
private static string password = "xgsnetwork-2012"; //MD5加密前专用密码
private Socket client;
private string code; //GET_KONE_CODE获取到验证码
private string key; //MD5加密后取前8位所得密钥
private byte[] data;
IPEndPoint ipep;
public string Code
{
get
{ return this.code; }
}
#region 构造方法
/// <summary>
/// 使用IP初始化
/// </summary>
/// <param name="host">终端IP</param>
public FaSong(string host)
{
data = new byte[1024];
ipep = new IPEndPoint(IPAddress.Parse(host), clientPort);
client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes("GET_KONE_CODE");
client.SendTo(data, data.Length, SocketFlags.None, ipep); //发送数据
//接收数据
IPEndPoint sender = new IPEndPoint(IPAddress.Parse(host), replyPort);
EndPoint Remote = (EndPoint)sender;
data = new byte[1024];
code = Encoding.ASCII.GetString(data, 0, client.ReceiveFrom(data, ref Remote));
//MD5加密后得到接口发送key
MD5 md5 = new MD5CryptoServiceProvider();
byte[] md5Data = Encoding.Default.GetBytes(code + password);
byte[] str = md5.ComputeHash(md5Data);
md5.Clear();
//得到加密后key取前8位
for (int i = 0; i < 4; i++)
{
this.key += str[i].ToString("x").PadLeft(2, '0');
}
}
#endregion
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
namespace WK
{
/// <summary>
/// 用于向终端发送各播控接口
/// </summary>
class FaSong
{
private static int clientPort = 7001; //终端接收端口
private static int replyPort = 7000; //终端答复端口
private static string password = "xgsnetwork-2012"; //MD5加密前专用密码
private Socket client;
private string code; //GET_KONE_CODE获取到验证码
private string key; //MD5加密后取前8位所得密钥
private byte[] data;
IPEndPoint ipep;
public string Code
{
get
{ return this.code; }
}
#region 构造方法
/// <summary>
/// 使用IP初始化
/// </summary>
/// <param name="host">终端IP</param>
public FaSong(string host)
{
data = new byte[1024];
ipep = new IPEndPoint(IPAddress.Parse(host), clientPort);
client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes("GET_KONE_CODE");
client.SendTo(data, data.Length, SocketFlags.None, ipep); //发送数据
//接收数据
IPEndPoint sender = new IPEndPoint(IPAddress.Parse(host), replyPort);
EndPoint Remote = (EndPoint)sender;
data = new byte[1024];
code = Encoding.ASCII.GetString(data, 0, client.ReceiveFrom(data, ref Remote));
//MD5加密后得到接口发送key
MD5 md5 = new MD5CryptoServiceProvider();
byte[] md5Data = Encoding.Default.GetBytes(code + password);
byte[] str = md5.ComputeHash(md5Data);
md5.Clear();
//得到加密后key取前8位
for (int i = 0; i < 4; i++)
{
this.key += str[i].ToString("x").PadLeft(2, '0');
}
}
#endregion