资源简介
MIKROTIK ROS API C#版,解决中文乱码,支持用户名,中文备注
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
using System.Windows.Forms;
namespace ROSAPI
{
class MK //ROS API类
{
Stream connection;
TcpClient con;
public MK(string ip)//连接实例
{
con = new TcpClient();
con.Connect(ip 8728);
connection = (Stream)con.GetStream();
}
public void Close()//连接关闭
{
connection.Close();
con.Close();
}
public bool Login(string username string password)//登陆ROS
{
Send(“/login“ true);
string hash = Read()[0].Split(new string[] { “ret=“ } StringSplitOptions.None)[1];
Send(“/login“);
Send(“=name=“ + username);
Send(“=response=00“ + EncodePassword(password hash) true);
if (Read()[0] == “!done“)
{
return true;
}
else
{
return false;
}
}
public void Send(string co)//发送参数,发送修改命令,操作ROS
{
//byte[] bajty = Encoding.ASCII.GetBytes(co.ToCharArray());
byte[] bajty = Encoding.Default.GetBytes(co.ToCharArray());//转为中文编码
byte[] velikost = EncodeLength(bajty.Length);
connection.Write(velikost 0 velikost.Length);
connection.Write(bajty 0 bajty.Length);
}
public void Send(string co bool endsentence)//读取服务器数据
{
byte[] bajty = Encoding.Default.GetBytes(co.ToCharArray());//转为中文编码
byte[] velikost = EncodeLength(bajty.Length);
connection.Write(velikost 0 velikost.Length);
connection.Write(bajty 0 bajty.Length);
connection.WriteByte(0);
}
public List Read()//读取数据
{
List output = new List();
string o = ““;
byte[] tmp = new byte[4];
long count;
while (true)
{
tmp[3] = (byte)connection.ReadByte();//读取Stream返回的数据,就是ROS返回的数据
//if(tmp[3] == 220) tmp[3] = (byte)connection.ReadByte(); it sometimes happend to me that
//mikrotik send 220 as some kind of “bonus“ between words this fixed things not sure about it though
if (tmp[3] == 0)//返回空
{
output.Add(o);//返回空,T类output则为加字符串o的值
if (o.Substring(0 5) == “!done“)
{
break;
}
else
{
o = ““;
continue;
}
}
else
{
if (tmp[3] < 0x80
相关资源
- WinCE访问WebAPI及Json切换功能
- C# CoreAudioApi封装库
-
IronPython.dll和Microsoft.sc
ripting.dll - C# API 大全
- C# lua库 支持中文函数名中文变量
- C#设计模式手册(中文CHM)
- zotero使用的中国引文样式.csl文件
- C# SAPI 语音交互系统
- c#调用 windows api实现WinForm中嵌入EXE程
- Microsoft.DirectX.DirectSound.dll和Microsoft.
- 解决GDAL读取shp文件属性和中文乱码问
- 淘宝、天猫、京东 API接口样例,C# 非
- C#调用考勤机API读取记录
- C# Language Specification 中文版
- csharp language specification chinese c#5.0 官方
- Prism7.1.0.431_WPF_官方中文文档
- WPF Charts控件库的全面扩展(最新201
- C# PDF iTextSharp教程中文+代码
- C#本质论(中文版).pdf
- C#.NET版微信支付API官方demo修改版降低
- C#调用高德、百度及google地图api解析经
- c#、unity3d实现远程视频通话源码NN视频
- NHapiC#的使用说明
- 小程序使用ASP.NET Web Api 作服务端实现
- c# Imap收信组件,UTF-8版本,完美支持
- Microsoft.Jet.OLEDB.4.0 及 Microsoft.ACE.OLED
-
Microsoft .NET fr
amework 4.5 - c#高级编程第10版 中文完整版
- C#调用微软在线翻译API实现简单的翻译
- .Net Reflector 9.0中文破解版
评论
共有 条评论